Identity verification

iOS SDK - Onfido

338 views December 5, 2019 March 25, 2020 0

Page overview:


  • SDK supports iOS 9+
  • SDK supports Xcode 10.2
  • App permission for Camera and Microphone

Import the SDK

  1. Make sure you have downloaded and installed the latest version of CocoaPods.
  2. Add the following row to your Podfile:
    pod 'Onfido'
  3. Run pod install
  4. Make sure you use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on.

Using the SDK

This is what you will need to do during Step D1: Launch provider SDK:

  • Create a new UIViewController that will contain the SDK.
  • Use the “authorization” token (<AUTHORIZATION_TOKEN>) you got during Step C: Create Process.
  • Write the code to handle the scenarios when the user has completed the process, or in case of an error.

The code below provides an example of this:

import UIKit
import Onfido
final class ViewController: UIViewController {
    init(authorization: authorization) {
        self.authorization = authorization
    override func viewDidLoad() {
        self.runFlow(authorization: self.authorization)
    private func runFlow(authorization: String) { // Use the <AUTHORIZATION_TOKEN> here
        let responseHandler: (OnfidoResponse) -> Void = { response in
            if case let OnfidoResponse.error(innerError) = response {
            } else if case OnfidoResponse.success = response {
            } else if case OnfidoResponse.cancel = response {
                print("Canceled by user")
        let faceStep = PhotoStepConfiguration())
        let config = try! OnfidoConfig.builder()
            .withFaceStep(ofVariant: faceStep)
        let onfidoFlow = OnfidoFlow(withConfiguration: config)
            .with(responseHandler: responseHandler)
        do {
            let onfidoRun = try
            onfidoRun.modalPresentationStyle = .formSheet // to present modally
            self.present(onfidoRun, animated: true, completion: nil)
        } catch let error {
           // cannot execute the flow
           // Check section below for list of most common errors

Error handling

One of the most common errors may be related to the camera permissions, so that is one of the things you should look for in case of an error.

Also, the following errors related to Onfido may occur:

OnfidoConfigError Info
missingToken When no or empty string token is provided.
missingApplicant When no applicant instance is provided.
missingSteps When no step is provided.
multipleApplicants When both an applicant and an applicantId are provided.
multipleTokenTypes When both an SDK Token and a Mobile Tokens are provided.
applicantProvidedWithSDKToken When both an SDK Token and an applicant are provided.


OnfidoFlowError Info
cameraPermission If access to the camera to the app has been denied.
exception(withError: Error?, withMessage: String?) It happens when an unexpected error occurs.
failedToWriteToDisk It happens when the SDK tries to save the capture to disk, maybe due to a lack of space.
microphonePermission If access to the microphone to the app has been denied.
upload(Onfido.OnfidoApiError) It happens when the SDK receives an error from an API.


The code example above will allow you to use Onfido’s basic flow with their default design. If you want to do some customization, check the next sections to know more about what you can change.

Default design

Welcome screen

You can customize the SDK to show the welcome screen.

Code to show the welcome screen:

private func runFlow(authorization: String) {
    let config = try! OnfidoConfig.builder()

Document type and country selection screen

Create your own selection screen.

private func runFlow(authorization: String) {
    guard let coutryCode = metadata.documentType?.country else { return }
    guard let documentType = metadata.documentTypeEnum?.typeCastingForOnfido()  else { return }
    let config = try! OnfidoConfig.builder()
        .withDocumentStep(ofType: documentType, andCountryCode: coutryCode) // Flow customisation, documents select

The .withDocumentStep requires Country code (3-letter ISO-3166-1 ALPHA-3 country code) and also Onfido DocumentType.

public enum DocumentType {
    case passport
    case drivingLicence
    case nationalIdentityCard
    case residencePermit

Main colors

public func getOnfidoAppearance() -> Appearance {
    let appearance = Appearance(
        primaryTitleColor: UIColor.white,,
        secondaryBackgroundPressedColor: UIColor.grey,
        fontRegular: "OpenSans-Regular",
        fontBold: "OpenSans-Bold",
        supportDarkMode: false)
    return appearance

Was this helpful?