# iOS SDK callbacks and handlers
Handlers and callbacks are optional. Use them if required, but we recommend setting at least tokenExpirationHandler to ensure that the access token remains valid.
# Status update notification
Use the onStatusDidChange callback to receive notifications about verification process steps.
This callback takes two parameters:
sdk— the SDK instance,prevStatus— the previous status.
After that, you can check sdk.status to determine the current verification status.
sdk.onStatusDidChange { (sdk, prevStatus) in
print("onStatusDidChange: [\(sdk.description(for: prevStatus))] -> [\(sdk.description(for: sdk.status))]")
switch sdk.status {
case .ready:
// Technically `.ready` cannot be passed here because the callback was set after the `status` had already become `.ready`.
break
case .failed:
print("failReason: [\(sdk.description(for: sdk.failReason))] - \(sdk.verboseStatus)")
case .initial:
print("No verification steps are passed yet")
case .incomplete:
print("Some but not all of the verification steps have been passed over")
case .pending:
print("Verification is pending")
case .temporarilyDeclined:
print("Applicant has been temporarily declined")
case .finallyRejected:
print("Applicant has been finally rejected")
case .approved:
print("Applicant has been approved")
}
}
# Event notification
Use the onEvent callback to receive notifications about events that occur during processing.
Each event is passed as an instance of a class inherited from the base class CBREvent. Every event includes:
eventType — the event type,
payload — a dictionary containing event parameters.
Depending on your needs, you can access the event parameters either by analyzing the payload directly or by casting the passed event instance to the corresponding CBREvent* class depending on its type.
sdk.onEvent { (sdk, event) in
switch event.eventType {
case .applicantLoaded:
if let event = event as? CBREventApplicantLoaded {
print("onEvent: Applicant [\(event.applicantId)] has been loaded")
}
case .stepInitiated:
if let event = event as? CBREventStepInitiated {
print("onEvent: Step \(event.idDocSetType) has been initiated")
}
case .stepCompleted:
if let event = event as? CBREventStepCompleted {
print("onEvent: Step \(event.idDocSetType) has been \(event.isCancelled ? "cancelled" : "fulfilled")")
}
case .analytics:
if let event = event as? CBREventAnalytics {
print("onEvent: Analytics event [\(event.eventName)] has occured with payload=\(event.eventPayload ?? [:])")
}
@unknown default:
print("onEvent: eventType=\(event.description(for: event.eventType)) payload=\(event.payload)")
}
}
# SDK completion notification
Use the onDidDismiss callback to receive a notification when the SDK is closed.
sdk.onDidDismiss { (sdk) in
print("onDidDismiss: sdk has been dismissed with status [\(sdk.description(for: sdk.status))]")
}
# Token expiration
Since the access token (accessToken) has a limited lifetime, you need to handle the case when it expires and must be refreshed.
The tokenExpirationHandler calls your server, retrieves a new token, and then provides it back to the SDK by calling the onComplete closure.
sdk.tokenExpirationHandler { (onComplete) in
get_token_from_your_backend { (newToken) in
onComplete(newToken)
}
}
The onComplete closure must be called even if you cannot provide a new token, in that case, pass nil.
# Verification completion
Use the verificationHandler to get a notification when the verification process has finished with a final decision.
The isApproved parameter indicates whether the applicant was approved or finally rejected. If you want to receive notifications about other verification statuses, use onStatusDidChange. See Status update notifications for details.
sdk.verificationHandler { (isApproved) in
print("verificationHandler: Applicant is " + (isApproved ? "approved" : "finally rejected"))
}
# Dismissal control
You can take control of SDK dismissal by assigning a dismissHandler. The handler receives the current sdk instance and the mainVC controller. You can close mainVC in any way you see fit.
sdk.dismissHandler { (sdk, mainVC) in
mainVC.dismiss(animated: true, completion: nil)
}