iOS

1. Installation

How to install Preventor iOS SDK

Requirements

The latest stable version of Xcode, since the SDK is written in Swift 5.7.1

Minimum target: iOS 13.0.

Install via CocoaPods

To always use the latest release, add the following to your Podfile:

pod 'PreventorSDK'

Alternatively, pin to a specific version (e.g. 0.2.2):

pod 'PreventorSDK', '2.1.0'

And then run:

pod install

Install via Swift Package Manager

import PackageDescription

let package = Package(
  name: "YourTestProject",
  platforms: [
       .iOS(.v13),
  ],
  dependencies: [
    .package(name: "PreventorSDK", url: "https://github.com/preventorid/button-ios-sdk.git", from: "2.1.0)
  ],
  targets: [
    .target(name: "YourTestProject", dependencies: ["PreventorSDK"])
  ]
)

Adding it to an existent iOS Project via Swift Package Manager

  1. Using Xcode go to File > Swift Packages > Add Package Dependency

  2. Click on next and select the project target

  3. Don't forget to set DEAD_CODE_STRIPPING = NO in your Build Settings (https://bugs.swift.org/plugins/servlet/mobile#issue/SR-11564)

2. Initialize SDK

For integration, you need to configure the pre-padding shown below. You must first implement the PSDKConfig structure.

Credential prefill

self.config = PSDKConfig(flowID: "YOUR_FLOW_ID",
                         cifCode: "YOUR_CIFCODE",
                         apiKey: "YOUR_API_KEY",
                         tenant: "YOUR_TENANT",
                         env: "YOUR_ENV",
                         banknu: "YOUR_BANKNU",
                         secret: "YOUR_CLIENT_SECRET",
                         invitation: "YOUR_INVITATION_ID",
                         broker: "YOUR_BROKER")

If the cifCode is empty or nil, a unique code is assigned.

To initialize the SDK, you need to call the initialize(config: PSDKConfig) method:

self.config = PSDKConfig(flowID: "YOUR_FLOW_ID",
                         cifCode: "YOUR_CIFCODE",
                         apiKey: "YOUR_API_KEY",
                         tenant: "YOUR_TENANT",
                         env: "YOUR_ENV",
                         banknu: "YOUR_BANKNU",
                         secret: "YOUR_CLIENT_SECRET",
                         invitation: "YOUR_INVITATION_ID",
                         broker: "YOUR_BROKER")
PSDK.shared.initialize(config: config)

3. Start the Verification

To start a new verification, you first need to create the PreventorButton

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 PreventorButton. Ensure that the module also says PreventorSDK below the class.

Add PreventorButton in your project programmatically

import SwiftUI
import PreventorSDK

struct ContentView: View {
    
    @ObservedObject var store: ContentViewModel
    let config: PSDKConfig
    
    var body: some View {
        PreventorButton()
    }
    
    init() {
        self.config = PSDKConfig(flowID: "YOUR_FLOW_ID",
                                 cifCode: "YOUR_CIFCODE",
                                 apiKey: "YOUR_API_KEY",
                                 tenant: "YOUR_TENANT",
                                 env: "YOUR_ENV",
                                 banknu: "YOUR_BANKNU",
                                 secret: "YOUR_CLIENT_SECRET",
                                 invitation: "YOUR_INVITATION_ID",
                                 broker: "YOUR_BROKER")
        PSDK.shared.initialize(config: config) { isSuccessful in
             //your code
        }
    }
}

class ContentViewModel: ObservableObject, PSDKDelegate {
    //YOUR IMPLEMENTATION
    func updatePreventorSDKDelegate() {
        PSDK.shared.delegate = self
    }

    func onStart() {
        print("onStart")
    }
    
    func onFinish(result: PSDKResult) {
        print("onFinish")
    }
    
    func onError(error: PSDKErrorCode) {
        print("error:", error.rawValue)
    }
    
    func onSubmitted(result: PSDKResult) {
        print("onSubmitted")
    }
    
}

Start Verification

To start a check, just click the PreventorButton

Adjust Your App's Permissions

If you made it until here, you've successfully installed the Preventor 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 Preventor 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>NSLocationWhenInUseUsageDescription</key>
<string>Please give us access to your location to complete the verification.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Please give us access to your location to complete the verification.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Please give us access to your photo library to verify you.</string>
<key>NFCReaderUsageDescription</key>
<string>Give us NFC access to complete verification.</string>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
	<string>TAG</string>
</array>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
	<string>A0000002471001</string>
	<string>E80704007F00070302</string>
	<string>A000000167455349474E</string>
	<string>A0000002480100</string>
	<string>A0000002480200</string>
	<string>A0000002480300</string>
	<string>A00000045645444C2D3031</string>
</array>

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

Customization

If you want to add your own customization you can use the following methods

4. Handling Verifications

To find out if a user started, completed, canceled or failed the verification process, you can implement the following delegate methods:

import SwiftUI
import PreventorSDK


struct ContentView: View {
    
    @ObservedObject var store: ContentViewModel
    let config: PSDKConfig
    
    var body: some View {
        PreventorButton()
    }
    
    init() {
        self.config = PSDKConfig(flowID: "YOUR_FLOW_ID",
                                 cifCode: "YOUR_CIFCODE",
                                 apiKey: "YOUR_API_KEY",
                                 tenant: "YOUR_TENANT",
                                 env: "YOUR_ENV",
                                 banknu: "YOUR_BANKNU",
                                 secret: "YOUR_CLIENT_SECRET",
                                 invitation: "YOUR_INVITATION_ID",
                                 broker: "YOUR_BROKER")
        PSDK.shared.initialize(config: config) { isSuccessful in
             //your code
        }
    }
}

class ContentViewModel: ObservableObject, PSDKDelegate {
    //YOUR IMPLEMENTATION
    func updatePreventorSDKDelegate() {
        PSDK.shared.delegate = self
    }

    func onStart() {
        print("onStart")
    }
    
    func onFinish(result: PSDKResult) {
        print("onFinish")
    }
    
    func onError(error: PSDKErrorCode) {
        print("error:", error.rawValue)
    }
    
    func onSubmitted(result: PSDKResult) {
        print("onSubmitted")
    }
    
}

Last updated