onfido-sdk-ios
Import the SDK
For advice about which SDK version you should download, see the Requirements section.
To import the SDK package, do the following steps:
-
Make sure you have downloaded and installed the latest version of CocoaPods.
-
Add the following row to your
Podfile:pod 'Onfido', '~> 23.0.1' -
Run
pod install. -
Make sure you use the
.xcworkspacefile to open your project in Xcode, instead of the.xcodeprojfile, from here and onwards.
Initialise and run the SDK (Swift code example)
Start the Onfido Mobile SDK by setting the SDK field withSDKToken with the authorization that you received in the backend response.
Sample code for starting the SDK:
import UIKit
import Onfido
final class ViewController: UIViewController {
let authorization = String
init(authorization: authorization) {
self.authorization = authorization
super.init()
}
override func viewDidLoad() {
super.viewDidLoad()
self.runFlow(authorization: self.authorization)
}
private func runFlow(authorization: String) {
let responseHandler: (OnfidoResponse) -> Void = { response in
if case let OnfidoResponse.error(innerError) = response {
print(innerError)
} else if case OnfidoResponse.success = response {
print("Success")
} else if case OnfidoResponse.cancel = response {
print("Canceled by user")
}
}
let faceStep = FaceStepVariant.photo(withConfiguration: PhotoStepConfiguration())
let config = try! OnfidoConfig.builder()
.withSDKToken(authorization)
.withWelcomeStep()
.withDocumentStep()
.withFaceStep(ofVariant: faceStep)
.build()
let onfidoFlow = OnfidoFlow(withConfiguration: config)
.with(responseHandler: responseHandler)
do {
let onfidoRun = try onfidoFlow.run()
onfidoRun.modalPresentationStyle = .formSheet // to present modally
self.present(onfidoRun, animated: true, completion: nil)
} catch let error {
// cannot execute the flow
// check CameraPermissions
print(error)
}
}
}
Customisation
Welcome screen
You can decide if you want to show a pre-defined Onfido welcome screen:
...
let config = try! OnfidoConfig.builder()
.withWelcomeStep()
...
.build()
Face match
You can perform the face match in two possible ways, either by asking the user to take a selfie photo or to make a live video recording. The Onfido API will then later on compare this photo/video with images retrieved from the identity documents and run a facial similarity check.
Face match with photo
Use the following sample code when the user is required to take a selfie photo:
let stepConfig = VideoStepConfiguration(showIntroVideo: true)
let facePhto = FaceStepVariant.photo(withConfiguration: PhotoStepConfiguration()
let config = try! OnfidoConfig.builder()
...
.withFaceStep(ofVariant: facePhoto)
...
.build()
Face match with live video recording
Performing a face match with a live video recording adds extra security to the identification. In this case, the user is asked to move their head and read random numbers displayed on the device screen.
Use the following sample code when the user is required to make a live video recording:
let stepConfig = VideoStepConfiguration(showIntroVideo: true)
let faceVideo = FaceStepVariant.video(withConfiguration: stepConfig)
let config = try! OnfidoConfig.builder()
...
.withFaceStep(ofVariant: faceVideo)
...
.build()