Cocoapods

Rx-Ver-ID-Apple

Reactive implementation of Ver-ID for iOS

Installation

  1. Register your app. You will need your app’s bundle identifier.
  2. Registering your app will generate an evaluation licence for your app. The licence is valid for 30 days. If you need a production licence please contact Applied Recognition.
  3. When you finish the registration you’ll receive a file called Ver-ID identity.p12 and a password. Copy the password to a secure location and add the Ver-ID identity.p12 file in your app:
    • Open your project in Xcode.
    • From the top menu select File/Add files to “[your project name]”… or press ⌥⌘A and browse to select the downloaded Ver-ID identity.p12 file.
    • Reveal the options by clicking the Options button on the bottom left of the dialog.
    • Tick Copy items if needed under Destination.
    • Under Added to targets select your app target.
  4. Ver-ID will need the password you received at registration.

    • You can either specify the password when you create an instance of RxVerID:

      let rxVerID = RxVerID(veridPassword: "your password goes here")
      
    • Or you can add the password in your app’s Info.plist:

      <key>com.appliedrec.verid.password</key>
      <string>your password goes here</string>
      
  5. If your project is using CocoaPods for dependency management, open the project’s Podfile. Otherwise make sure CocoaPods is installed and in your project’s folder create a file named Podfile (without an extension).

  6. Let’s assume your project is called MyProject and it has an app target called MyApp. Open the Podfile in a text editor and enter the following:

    project 'MyProject.xcodeproj'
    workspace 'MyProject.xcworkspace'
    platform :ios, '11.0'
    target 'MyApp' do
        use_frameworks!
        pod 'Rx-Ver-ID'
    end
    
  7. Save the Podfile. Open Terminal and navigate to your project’s folder. Then enter:

    pod install
    
  8. You can now open MyProject.xcworkspace in Xcode and Rx-Ver-ID will be available to use in your app MyApp.

Examples

Detect a face in an image and crop the image to the bounds of the face

import RxVerID
import RxSwift

// Create an instance of RxVerID
let rxVerID = RxVerID()
// Set this to a file URL of an image with a face
let url = URL(fileURLWithPath: "test.jpg")
rxVerID.detectFacesInImageURL(url, limit: 1) // Detect one face
    .single() // Convert observable to single
    .flatMap { face in
        rxVerID.cropImageURL(url, toFace: face) // Crop the image
    }
    .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default)) // Subscribe on a background thread
    .observeOn(MainScheduler()) // Observe on main thread
    .subscribe(onNext: { image in
      // The image is an instance of UIImage. You can display the image in an image view, save it, etc.
    }, onError: { error in
      // Something went wrong, inspect error
    }, onCompleted: nil, onDisposed: nil)

Detect a face in an image and assign it to a user

import RxVerID
import RxSwift

// Create an instance of RxVerID
let rxVerID = RxVerID()
// Set this to a file URL of an image with a face
let url = URL(fileURLWithPath: "test.jpg")
// Set this to an identifier for your user
let userId = "testUserId"
rxVerID.detectRecognizableFacesInImageURL(url, limit: 1) // Detect one face
    .single() // Convert observable to single to ensure one face was found
    .flatMap { face in
        rxVerID.assignFace(face, toUser: userId) // Assign the detected face to user
    }
    .asCompletable()
    .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default)) // Subscribe on a background thread
    .observeOn(MainScheduler()) // Observe on main thread
    .subscribe(onCompleted: {
      // The face has been assigned to user "testUserId"
    }, onError: { error in
      // Something went wrong, inspect error
    })

Authenticate user in an image

import RxVerID
import RxSwift

// Create an instance of RxVerID
let rxVerID = RxVerID()
// Set this to a file URL of an image with a face
let url = URL(fileURLWithPath: "test.jpg")
// Set this to an identifier for your user
let userId = "testUserId"
rxVerID.authenticateUser(userId, inImageURL: url) // Detect one face
    .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default)) // Subscribe on a background thread
    .observeOn(MainScheduler()) // Observe on main thread
    .subscribe(onSuccess: { authenticated in
        if authenticated {
            // The image has been authenticated as user "testUserId"
      }
    }, onError: { error in
      // Something went wrong, inspect error
    })

Identify users in image

import RxVerID
import RxSwift

// Create an instance of RxVerID
let rxVerID = RxVerID()
// Set this to a file URL of an image with a face
let url = URL(fileURLWithPath: "test.jpg")
rxVerID.identifyUsersInImageURL(url) // Identify users
    .single() // Fail if no users or more than one user are identified
    .map { userScoreTuple in
        userScorePair.0 // We only need the user ID without the score
    }
    .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default)) // Subscribe on a background thread
    .observeOn(MainScheduler()) // Observe on main thread
    .subscribe(onNext: { userId in
        // Identified userId
    }, onError: { error in
        // Something went wrong, inspect error
    }, onCompleted: nil, onDisposed: nil)

Run a Ver-ID session

import RxVerID
import RxSwift

// Create an instance of RxVerID
let rxVerID = RxVerID()
// Create a dispose bag
let disposeBag = DisposeBag()
// Create session settings
let settings = LivenessDetectionSessionSettings()
rxVerID.session(settings: settings)
    .subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default))
    .observeOn(MainScheduler.instance)
    .subscribe(onSuccess: { result in
        // Session succeeded 
    }, onError: { error in
        // Session failed
    }, onCompleted: {
        // Session was cancelled
    })
    .disposed(by: disposeBag)

Advanced options

If you’re not planning to run Ver-ID sessions using RxVerID you can decrease the footprint of your app by only including the core part of the library. To do that change the pod spec to:

pod 'Rx-Ver-ID/Core'

Reference documentation