Accounts SDK for iOS

The Accounts SDK is a solution to ease the integration with the Alviere services.

Features

  • User Account Management
  • User Addresses Management

Requirements

  • iOS 11.0+
  • Xcode 12+
  • Swift 5.3+

Installation

Swift Package Manager

1. Add the dependency to your project. Open your project and navigate to your project’s settings. Select the tab named Swift Packages and click on the add button + at the bottom left.

image

2. Enter the url of Accounts SDK for the iOS repository (https://github.com/Alviere/alviere-accounts-ios) in the text field and click Next.

image

3. On the next screen, select the SDK version and click Next.

image

4. Select the Payments package and click Finish.

image

5. Repeat the same process for AlCore SDK (https://github.com/Alviere/alviere-core-ios). The current version is compatible with AlCore SDK version 0.9.0 and up.

CocoaPods

1. Get the latest version of CocoaPods, if you haven’t already.

2. Create the Podfile by running the following command, if you don’t have one already.

pod init

3. Add this line to your Podfile.

pod 'AccountsSDK'

4. Run the following command to install the library. Also, run this to update to newer releases in the future.

pod install

Carthage

1. Get the latest version of Carthage, if you haven’t already.

2. Add the following entries in your Cartfile:

binary https://raw.githubusercontent.com/Alviere/alviere-core-ios/master/AlCore.json
binary https://raw.githubusercontent.com/Alviere/alviere-accounts-ios/master/AccountsSDK.json

3. Run the following command to download the latest version of the SDK.

carthage update --use-xcframeworks

4. Follow the Manual instructions below to embed the SDK into your project.

Manual

1. Get the latest versions of AccountsSDK.xcframework, its dependencies, and AlCore.xcframework and embed it into your application by dragging and dropping the files onto the Frameworks, Libraries and Embedded Content project section, as shown below.

image

2. Depending on the location of the xcframeworks on the filesystem you may need to change the Framework Search Paths build setting to avoid the error: fatal error: ‘AccountsSDK/AccountsSDK.h’ file not found. For example, the Xcode project below have it set to FRAMEWORK_SEARCH_PATHS = $(PROJECT_DIR)/../ since the xcframeworks files are shared between them and are kept in the directory that also contains the project directories.

image

Usage

To initialize the Accounts SDK for iOS, you need to set the Environment at the entry point of your application. For example, you can do this on your AppDelegate file on the application(_:,didFinishLaunchingWithOptions:) method, as shown below.

import AlCore

...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Setup Alviere SDK.
    if !AlCoreSDK.shared.setEnvironment(.sandbox) {
        print("Error initializing SDK.")
    }
    return true
}

After this setup, you just need to import the Accounts SDK for iOS on the files where you want to use the features.

import AccountsSDK

User Account Management

Adopt the AccountDelegate Protocol

This can be handled, for instance, by the view controller object that will call the user account actions.

extension ViewController : AccountDelegate

The AccountDelegate methods are the main communication back channel to your application for the user account management on Accounts SDK for iOS. For each action there is one method associated as follows:

  • Get: didGetUserAccount(_:)
  • Update: didUpdateUserAccount(_:)

There is also a global method didHandleEvent(_,metadata:) to receive events, like errors for instance. This enables your application to gain further insight into what is going on as the user goes through the Accounts SDK flow. In case of an error you may want to display error related information to the user and have them try doing the action again.

func didHandleEvent(_ event: String, metadata: [String : String]?) {
    print("Received event: \(event)\nmetadata: \(metadata ?? [:])")
}

The event keys are defined on the Event enum and the metadata keys on Metadata enum.

Get User Account

To get a user account, use getUser where you will need to create a new auth_token, pass the accountUuid value, and pass the AccountDelegate delegate instance.

AlAccounts.shared
    .getUser(token: authToken,
             accountUuid: accountUuid,
             delegate: self)

The result of this action will return the User details model on didGetUserAccount(_:) delegate method. Any errors will be returned on didHandleEvent(_,metadata:) delegate method.

func didGetUserAccount(_ user: User) {
    print("User account is:\n\(user)")
}

Update User Account

To update a user account, use updateUser where you will need to create a new auth_token, pass the accountUuid value, pass the PersonalInformation model with the user data updated, and pass the AccountDelegate delegate instance.

let userData = PersonalInformation( ... )

AlAccounts.shared
    .updateUser(token: authToken,
                accountUuid: accountUuid,
                userData: userData,
                delegate: self)

The result of this action will return the updated User model on didUpdateUserAccount(_:) delegate method. Any errors will be returned on didHandleEvent(_,metadata:) delegate method.

func didUpdateUserAccount(_ user: User) {
    print("Updated user account is:\n\(user)")
}

User Addresses Management

Adopt the AccountAddressDelegate Protocol

This can be handled, for instance, by the view controller object that will call the user account actions.

extension ViewController : AccountAddressDelegate

The AccountAddressDelegate methods are the main communication back channel to your application for the user addresses management on Accounts SDK for iOS. For each action there is one method associated as follows:

  • Add: didAddUserAddress(_:)
  • Get all: didGetUserAddresses(_:)
  • Update: didUpdateUserAddress(_:)

There is also a global method didHandleEvent(_,metadata:) to receive events, like errors for instance. This enables your application to gain further insight into what is going on as the user goes through the Accounts SDK flow. In case of an error you may want to display error related information to the user and have them try doing the action again.

func didHandleEvent(_ event: String, metadata: [String : String]?) {
    print("Received event: \(event)\nmetadata: \(metadata ?? [:])")
}

The event keys are defined on the Event enum and the metadata keys on Metadata enum.

Add User Address

To add a user address to an account, use addAddress where you will need to create a new auth_token, pass the accountUuid value, pass the AddressRequest model with the user address data, and pass the AccountAddressDelegate delegate instance.

let model = AddressRequest( ... )

AlAccounts.shared
    .addAddress(token: authToken,
                accountUuid: accountUuid,
                addressData: model,
                delegate: self)

The result of this action will return the newly added UserAddress model on didAddUserAddress(_:) delegate method. Any errors will be returned on didHandleEvent(_,metadata:) delegate method.

func didAddUserAddress(_ address: UserAddress) {
    print("New user address is:\n\(address)")
}

Get User Addresses

To get all user addresses, use getAddresses where you will need to create a new auth_token, pass the accountUuid value, and pass the AccountAddressDelegate delegate instance.

AlAccounts.shared
    .getAddresses(token: authToken,
                  accountUuid: accountUuid,
                  delegate: self)

The result of this action will return an UserAddress array with the user addresses on didGetUserAddresses(_:) delegate method. Any errors will be returned on didHandleEvent(_,metadata:) delegate method.

func didGetUserAddresses(_ addresses: [UserAddress]) {
    print("User addresses are:\n\(addresses)")
}

Update User Address

To update a user address, use updateAddress where you will need to create a new auth_token, pass the accountUuid value, pass the addressId value, pass the UserAddress model with the address data updated, and pass the AccountAddressDelegate delegate instance.

let addressData = UserAddress( ... )

AlAccounts.shared
    .updateAddress(token: authToken,
                   accountUuid: accountUuid,
                   addressId: addressId,
                   addressData: addressData,
                   delegate: self)

The result of this action will return the updated UserAddress model on didUpdateUserAddress(_:) delegate method. Any errors will be returned on didHandleEvent(_,metadata:) delegate method.

func didUpdateUserAddress(_ address: UserAddress) {
    print("Updated user address is:\n\(address)")
}

Fraud Prevention Service

The Accounts SDK has a built-in fraud prevention service. This service is automatically activated when you Update an User Account. If you already have an account created and want to activate the service on the next app run you just need to set the accountUuid on the service as the user id. For example, you can do this on your AppDelegate file on the application(_:,didFinishLaunchingWithOptions:) method, as shown below.

import AlCore

...

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Setup Alviere SDK.
    if !AlCoreSDK.shared.setEnvironment(.sandbox) {
        print("Error initializing SDK.")
    }

    // Start fraud prevention service.
    AlCoreSDK.shared.setUserId(accountUuid)
    return true
}

To fully enable the service you need to do a small setup by adding the add the LSApplicationQueriesSchemes array in your Info.plist file. Right-click somewhere outside the table and select Add Row. Now add the entries like below.

image

Or if you prefer to do this step with code, right-click on Info.plist and select Open As > Source Code. Add the lines below somewhere inside the <dict> </dict>.

<!-- Fraud prevention setup to be included in Info.plist -->
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>cydia</string>
</array>

Customization

The Accounts SDK for iOS provides a set of UI styling and field validation customizations to allow you to adjust the provided UI to fit your needs by setting a style model. To customize the UI, start from the default style and make the changes.

var style = LoadingStyle.getDefaultStyle()
style.backgroundColor = UIColor.white
...

Styling

Below are the styling options provided that are used to compose style models like DocumentsStyle.

Class Attribute Description
ViewStyle backgroundColor UIColor that affects the background color of UIView
  darkBackgroundColor UIColor that affects the background color of UIView in dark mode
TextStyle color UIColor that affects the text color of UILabel
  darkColor UIColor that affects the text color of UILabel in dark mode
  font UIFont that affects the text font of UILabel
ButtonStyle backgroundColor UIColor that affects the background color of UIButton
  darkBackgroundColor UIColor that affects the background color of UIButton in dark mode
  titleStyle TextStyle that affects the text font and color of UIButton
  cornerRadius CGFloat that controls the corner radius of UIButton
  margins UIEdgeInsets that controls the margins of UIButton

Text and Localization

The Accounts SDK for iOS allows you to customize the UI text. To do so, you will need to redefine the localization key that you want to change on your Localizable.strings file. The next section details a list of the current localization keys. Currently, the SDK only provides english localization.

Localization Keys

Key English Value
alviere_sdk_accounts_documents_title_passport Passport
alviere_sdk_accounts_documents_title_driver_license_front Driver License Front
alviere_sdk_accounts_documents_title_driver_license_back Driver License Back
alviere_sdk_accounts_documents_title_selfie Face
alviere_sdk_accounts_documents_title_proof_of_address Proof of Address
alviere_sdk_accounts_documents_hint_glare Reduce glare
alviere_sdk_accounts_documents_hint_low_contrast Low contrast
alviere_sdk_accounts_documents_hint_busy_background Busy background
alviere_sdk_accounts_documents_hint_not_check_back Not check back
alviere_sdk_accounts_documents_hint_not_check_front Not check front
alviere_sdk_accounts_documents_hint_nothing Nothing detected
alviere_sdk_accounts_documents_hint_too_dim Too dim
alviere_sdk_accounts_documents_hint_too_bright Too bright
alviere_sdk_accounts_documents_hint_not_sharp Not sharp
alviere_sdk_accounts_documents_hint_rotation Reduce rotation
alviere_sdk_accounts_documents_hint_angle_too_large Angle too large
alviere_sdk_accounts_documents_hint_too_close Too close
alviere_sdk_accounts_documents_hint_too_far Too far
alviere_sdk_accounts_documents_hint_hold_steady Hold Still
alviere_sdk_accounts_documents_hint_face_center Center Face In The Oval
alviere_sdk_accounts_documents_hint_face_low_lighting Increase light on face
alviere_sdk_accounts_documents_hint_face_no_face No face detected
alviere_sdk_accounts_documents_hint_face_get_closer Get closer
alviere_sdk_accounts_documents_hint_face_get_farther Get farther
alviere_sdk_accounts_documents_hint_face_hold_device_upright Hold device upright
alviere_sdk_accounts_documents_hint_face_hold_still Hold still
alviere_sdk_accounts_documents_hint_face_stop_smiling Stop smiling
alviere_sdk_accounts_documents_hint_face_smile Smile!
alviere_sdk_accounts_documents_warning_not_portrait Hold device in portrait mode
alviere_sdk_accounts_documents_step Step %d of %d
alviere_sdk_accounts_documents_preview_title Looking good?
alviere_sdk_accounts_documents_preview_retake Take a new one
alviere_sdk_accounts_documents_preview_ok Yes
alviere_sdk_accounts_documents_completed_title Success
alviere_sdk_accounts_documents_uploading_title Uploading
alviere_sdk_accounts_documents_error_generic An error occurred.
alviere_sdk_accounts_documents_error_retry Tap to retry
alviere_sdk_loading_title Loading
alviere_sdk_error_title Error
alviere_sdk_error_try_again Try Again
alviere_sdk_error_generic An error has occurred
alviere_sdk_vo_loading_done Finished loading