iOS

This guide helps you integrate the Passbase SDK into your iOS App and start the verification flow

General

Please ensure that you are using the latest XCode version, since the SDK is written in Swift 5.3. As of this writing, this is Xcode 12.0. Please also install Cocoapods, if you haven't already.

Before integrating Passbase, we suggest you read first our best practice on how to integrate Passbase in your system in the overview section and complete the initial setup steps.

1. Install the SDK

Please use Cocoapods to install the SDK. If you don't have it installed already, please follow steps 1-2 from this guide.

If you don't have a Podfile in your project yet, please create one. To do this, open a terminal window. Then, navigate to your iOS project's folder and run:pod init

This will create a Podfile inside your project. Open this file and add the following code to the top of it:

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/passbase/zoomauthentication-cocoapods-specs.git'
source 'https://github.com/passbase/cocoapods-specs.git'
source 'https://github.com/passbase/microblink-cocoapods-specs.git'

Next, add the actual pod after the target of your app. Include also the iOS 11 requirement and use_frameworks!, like in the example below.

# 1. Add this here
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/passbase/zoomauthentication-cocoapods-specs.git'
source 'https://github.com/passbase/cocoapods-specs.git'
source 'https://github.com/passbase/microblink-cocoapods-specs.git'
# 2. Add iOS requirements
platform :ios, '11.0'
target 'YourApp' do
# 3. Add use_frameworks!
use_frameworks!
# 4. Add Passbase pod
pod 'Passbase'
end

Finally, run pod install to install the Passbase SDK in your project. This will create a new .xcworkspace file inside your project's folder. Please use this file for future development, since all dependencies are installed here.

If you need to update to the latest pod, use the command pod update inside your directory to pull the latest podspec version and get the latest version of the SDK.

You have successfully installed the Passbase SDK in your iOS application! 🎉

2. Initialize the SDK

Initialize the SDK in AppDelegate

Please use the publishable API key for all integrations. The secret key should never be exposed or used in a web integration or mobile app since it can access sensitive user data if leaked!

Open the Workspace file in your directory. This file was created through the previous step with CocoaPods. It will be called something like YourProject.xcworkspace.

Now, open your AppDelegate.swift file and add import Passbase to the top. Then add the initialize method with your publishable API key from your API settings. Your code should look now like below:

import Passbase
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
PassbaseSDK.initialize(publishableApiKey: "YOUR_PUBLISBALE_API_KEY")
return true
}
}

Adjust Your App's Permissions

If you made it until here, you've successfully installed the Passbase SDK for iOS. Now let's adjust your last settings and start your first verification.

Please add the following permissions to your app's Info.plist, so that the Passbase iOS SDK can access a user's camera to run a verification. You can do this in the property list view or by code.

Right-click somewhere outside the table and select Add Row. Now add the entries like below.

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>

<!-- permission strings to be include in info.plist -->
<key>NSCameraUsageDescription</key>
<string>Please give us access to your camera, to complete the verification.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Please give us access to your photo library to verify you.</string>

You have successfully finished setting up the Passbase iOS SDK! 🎉

3. Start a Verification

To start a new verification, you can either trigger it through the storyboard or by code. This section will walk you through both.

Keep in mind that in order to successfully finish a verification, you need to pass our liveness detection. Hence, if you develop on a Simulator (e.g. iPhone Simulator via Xcode), you will only see the UI Demo Mode of our SDK. Therefore please use a real device (e.g. an attached iPhone) to fully test and develop with our SDK.

Add Button via Storyboard

Two simple steps to get the button running:

  1. Drag a new button on your storyboard and give it your desired constraints.

  2. Subclass the button as PassbaseButton. Ensure that the module also says Passbase below the class.

That's it! The button should now be rendered and trigger the verification flow.

Add Button Programmatically

To start the verification flow programmatically, create a new button of type PassbaseButton. You can give it parameters, like width, height, x & y through the CGRect and add constraint to position the button.

//Add to the top of the file
import Passbase
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Add the button with dimensions
let button = PassbaseButton(frame: CGRect(x: 40, y: 90, width: 300, height: 60))
self.view.addSubview(button)
// Or Add button with autolayout support
let button = PassbaseButton(frame: .zero)
button.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(button)
let buttonConstraints = [
button.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 50.0),
button.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -50.0),
button.topAnchor.constraint(lessThanOrEqualTo: self.view.topAnchor, constant: 60.0),
button.heightAnchor.constraint(equalToConstant: 40),
]
NSLayoutConstraint.activate(buttonConstraints)
}
}

Prefilling Email Addresses

If you want to automatically prefill user's email address to skip the "Approve your Email" screen. This is available programmatically if you pass the prefillUserEmail parameter to the button like below.

import Passbase
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Pass in the end users email to skip screen
PassbaseSDK.prefillUserEmail = "testuser@yourproject.com"
let button = PassbaseButton(frame: CGRect(x: 40, y: 90, width: 300, height: 60))
self.view.addSubview(button)
}
}

You have successfully started your first verification. 🎉

4. Handling Verifications

In some cases it's useful to know if a user has completed the verification flow or canceled it. For this, you can implement the following delegate/callback methods:

Method

Description

onStart

This callback method is triggered once a user starts the verification flow.

onFinish

This callback method is triggered once a user completes the full verification flow. You receive an object called identityAccessKey which can be used to access the identity. Please see our section about Webhooks and API for more information.

onError

This callback method is triggered if a user canceled the verification flow or the verification flow finished with an error. You can use this to find out if people dropped out of your verification flow.

Error codes:

CANCELLED_BY_USER REAUTHENTICATION_FAILED

Code Example

import Passbase
import UIKit
// 1. Add PassbaseDelegate here
class ViewController: UIViewController, PassbaseDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// 2. Set the delegate object to self
PassbaseSDK.delegate = self
let button = PassbaseButton(frame: CGRect(x: 40, y: 90, width: 300, height: 60))
self.view.addSubview(button)
}
// 3. Implement the delegate methods
func onFinish(identityAccessKey: String) {
print("onFinish with identityAccessKey \(identityAccessKey)")
}
func onError(errorCode: String) {
print("onError with code \(errorCode)")
}
func onStart() {
print("onStart")
}
}

We recommend the following process for handling identity verifications:

  1. Obtain the identityAccessKey of a successful completed identity verification from the callback method and save it to your db to the user's profile

  2. Set up webhooks to be notified once the identity verification has been processed by our system. Also once you have approved or declined the user in your dashboard

  3. Now you can use your own backend to query the details about this identity verification with e.g. the Get Identity call to obtain the details

5. UI Customizations

Appearance

Our SDK currently supports a set of customization options which will influence the appearance. To customize the verification flow, please navigate to your developer dashboard's customization section. Here you can choose amongst a variety of colors, fonts, accepted countries & much more.

Customization Section

We also offer a darkmode, which will be automatically started if a user has activated this in his system settings.

Dark Mode

Language

We support a variety of different languages for the verification flow. As of this writing more than 10 including (English, Spanish, German & many more). If one is missing and you want us to add support for it, please reach out to our customer support.

The SDK automatically detects the language of the user's phone settings. If we support the language, the verification flow will be set to it. Otherwise the default is English.

Example & Demo App

The code below is a sample implementation of a class with prefilled email and button added via code. You can find a complete sample App with both approaches (Storyboard & programmatic) on our Github page.

Link: Passbase iOS Demo App

import Passbase
import UIKit
class ViewController: UIViewController, PassbaseDelegate {
override func viewDidLoad() {
super.viewDidLoad()
PassbaseSDK.delegate = self
// Optional - You can prefill the email to skip that step.
Passbase.prefillUserEmail = "testuser@yourproject.com"
let button = PassbaseButton(frame: CGRect(x: 40, y: 90, width: 300, height: 60))
self.view.addSubview(button)
}
func onFinish(identityAccessKey: String) {
print("onFinish with identityAccessKey \(identityAccessKey)")
}
func onError(errorCode: String) {
print("onError with code \(errorCode)")
}
func onStart() {
print("onStart")
}
}