Skip to main content

Initializing the SDK

After installing the SDK, you must initialize it with a profile token received from your server and the required customer information.

Import the SDK into your Swift file:

import Amani

SSL Pinning (Optional)​

SSL pinning provides an additional layer of security for network communication.

This configuration is optional. If you want to enable SSL pinning, it must be configured before calling initAmani.

The method throws an error if the SSL pinning configuration or certificate is invalid, so it should be called inside a do-catch block.

do {
try Amani.sharedInstance.setSSLPinning(certificate: certificateURL)
} catch {
print("SSL Pinning configuration failed: \(error)")
}

Creating the Customer​

Create a CustomerRequestModel before initializing the SDK.

The only required customer field is idCardNumber.

let customer = CustomerRequestModel(
name: "CUSTOMER_NAME", // Optional
email: "CUSTOMER_EMAIL", // Optional
phone: "CUSTOMER_PHONE_NUMBER", // Optional
idCardNumber: "CUSTOMER_ID_CARD"
)
note

The idCardNumber value must match the id_card_number field associated with the customer profile.

Accessing the SDK Instance​

AmaniSDK uses a shared instance.

let amani = Amani.sharedInstance

You can keep this reference inside your UIViewController or another class responsible for the verification flow.

Initializing the SDK​

Set the delegate before initializing the SDK.

override func viewDidLoad() {
super.viewDidLoad()

amani.setDelegate(delegate: self)

amani.initAmani(
server: "https://server.example",
token: token,
sharedSecret: "optional shared secret",
customer: customer,
apiVersion: .v2
) { [weak self] customerResponse, error in
if let error {
print("AmaniSDK initialization failed: \(error)")
return
}

guard let customerResponse else {
return
}

print("AmaniSDK initialized successfully")
print(customerResponse)
}
}

The SDK creates an active verification session during initAmani.

Session-specific information such as the active profile token and customer-related runtime information is available only while this session is active.

If initialization fails, handle the returned error and do not use SDK modules until initAmani completes successfully.

warning

You cannot use SDK modules before initAmani completes successfully.

Implementing AmaniDelegate​

Implement AmaniDelegate to receive profile updates, step results, and SDK errors.

extension ViewController: AmaniDelegate {

// Called when the customer profile status changes.
func onProfileStatus(
customerId: String,
profile: AmaniSDK.wsProfileStatusModel
) {
print(profile)
}

// Called when the status of a verification step changes.
func onStepModel(
customerId: String,
documentId: String,
rules: [AmaniSDK.KYCRuleModel]?
) {
print(rules)
}

// Called when an SDK, network, or verification error occurs.
func onError(
type: String,
error: [AmaniSDK.AmaniError]
) {
print(type)
print(error)
}
}

Ending the Session​

Call endSession() when the active verification session is no longer needed.

Typical cases include:

  • The customer completes the verification flow.
  • The customer cancels or leaves the verification flow.
  • The customer logs out.
  • Your application switches to another customer/profile.
  • You want to explicitly terminate the current Core SDK session.
let cleanupSucceeded = Amani.sharedInstance.endSession()

Calling endSession() immediately invalidates the active SDK session and clears customer-specific runtime state.

Session-scoped information such as the active SDK token, customer information, NVI/MRZ information, socket token, and other session-specific cached values is also removed.

Persistent SDK configuration that may be reused between sessions is not treated as customer session data.

Understanding the Return Value​

endSession() returns a Bool.

let cleanupSucceeded = Amani.sharedInstance.endSession()

if cleanupSucceeded {
print("AmaniSDK session ended successfully")
} else {
print("AmaniSDK session ended, but persistent session storage cleanup could not be verified")
}

A return value of true means that the SDK successfully removed and verified the session-scoped persistent data.

A return value of false does not mean that the previous SDK session is still active.

The active runtime session is invalidated regardless of the returned value.

When false is returned:

  • The previous SDK session must still be considered terminated.
  • Do not continue making requests using the previous session.
  • Do not attempt to reuse the previous profile token through the existing SDK session.
  • You may record the failure in your application logs or monitoring system.
  • Your application flow does not need to remain blocked.

For example:

let cleanupSucceeded = Amani.sharedInstance.endSession()

if !cleanupSucceeded {
// Optional:
// Record this event in your application's logging
// or monitoring system.
print("AmaniSDK session cleanup could not be verified")
}

// Continue closing your verification flow normally.

You normally do not need to repeatedly call endSession() until it returns true.

Starting Another Customer Session​

After calling endSession(), you must call initAmani again before using any SDK module.

Always use a valid profile token for the new customer.

_ = Amani.sharedInstance.endSession()

Amani.sharedInstance.initAmani(
server: "https://server.example",
token: newProfileToken,
customer: newCustomer,
apiVersion: .v2
) { customerResponse, error in
if let error {
print("New AmaniSDK session could not be started: \(error)")
return
}

print("New customer session started")
}

Before a new session becomes active, the SDK performs its session initialization and cleanup checks again.

If the SDK cannot establish a clean session, initAmani fails through its completion handler instead of starting the new customer session with stale session data.

This means applications using only the Core SDK do not need to manually manage SDK storage or Keychain state.

The recommended lifecycle is:

initAmani
↓
Use SDK modules
↓
Customer flow finishes / is cancelled / user logs out
↓
endSession
↓
Session is invalidated
↓
initAmani with a new profile token when another session is required
note

The return value of endSession() is optional to use. If your application does not need cleanup telemetry, you can simply call:

Amani.sharedInstance.endSession()

The SDK session will still be invalidated.

warning

Do not continue using SDK modules after calling endSession(). Call initAmani again before starting another verification operation.

Profile Status​

KeyTypeDescription
amlStatusBooleanAnti Money Laundering status
riskIntRange: 0-4. Shows the risk status of the profile
statusStringShows the general profile status, such as APPROVED, REJECTED, or PENDING
customerIdStringReturns the UUID of the connected profile

Steps Result​

KeyTypeDescription
resultArrayList of ResultReturns the verification steps associated with the profile
idStringReturns the unique ID of the step
statusStringShows the step status, such as APPROVED, REJECTED, or PENDING
sortOrderIntDefines the ordering of the step in the verification flow
errorsList of ErrorsContains errors that occurred while processing the step
titleStringReturns the configured title of the step, such as Selfie or Identification. Values shown in your debug environment depend on your profile configuration. Contact the Amani Team to modify the configuration

On Error​

KeyTypeDescription
typeStringIdentifies the SDK error category
errorArrayList of AmaniErrorContains the errors associated with the event

Types​

Error TypeDescription
login_errorErrors related to authentication
config_errorErrors related to fetching remote configuration
selfie_errorErrors related to the Selfie upload process
id_errorErrors related to the ID upload process
signature_errorErrors related to the Signature upload process
customer_errorErrors related to customer/profile services
bio_loginErrors related to Bio Login requests
socket_errorGeneral socket-related errors

Errors​

Error CodeError Message
10500Server connection problem
10501Connection Error
10400No configuration found
10404Image count did not match the required document image count
10100Profile ID not found
10101NFC response cannot be nil
10604SSL certificate format error
10502SSL Pinning Error