Skip to main content

IOS Integration

Facial Recognition Framework has been written in Swift. Please follow these steps for integrating this framework.

note

You can find sample project containing complete integration of SDK here (requires access).

Integration Guide (Swift)

Manual Linking

  • Download FacialRecognition.xcframework from this repository.
  • Add FacialRecognition.xcframework in your app.
  • Add FacialRecognition.xcframework in Embedded Binaries in Projects General Settings.

Pods Linking

For linking FacialRecognition library using CocoaPods you can add either:

  • FacialRecognition repository link with version tag in your Podfile
pod 'FacialRecognition', :git => "https://gitlab.com/fetchsky/identity-facial-sdk-lite-pod", :tag => "v2.0.0"

Use the latest communicated version of the framework.

  • Place FacialRecognition directory in your project root and its path in your Podfile
pod 'FacialRecognition', :path => "./FacialRecognition"

Run pod install in your terminal.

Using Library

link FacialRecognition in your ViewController

import FacialRecognition

conform to FacialRecognitionControllerDelegate protocol in your class, to handle events and results related to framework.

class ViewController: FacialRecognitionControllerDelegate { ....

Initialize Facial Recognition Controller

Create an instance of FacialRecognitionController with base64 encoded source image string.

override func viewDidLoad() {
super.viewDidLoad()
...
let facialController = FacialRecognitionController(source: base64String, blurThreshold: 100)
// Set Delegate
facialController.delegate = self
// Add as Child View Controller
addChild(facialController)
// Configure View Frame
facialController.view.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height)
// Add as Subview
view.addSubview(facialController.view)
// Notify Child View Controller
facialController.didMove(toParent: self)
}

Optional: Set blur threshold to validate if the captured frame is blurred or shaky. Default value is 100. Applicable with version >=2.0.0.

Add event handlers

class ViewController: FacialRecognitionControllerDelegate {
...
func handleError(code: String) {
// error code can be either:
// initialization_error, invalid_source, model_error, no_camera

// handle the error given by framework

}

func handleResponse(similarity: Double, faceImage: String) {
// similarity: float value of similarity of two faces betwee 1 and 0
// faceImage: base64 encoded image string of the face captured

// handle the responsne
}


Updating Info.plist

Add Privacy - Camera Usage Description in your app's Info.plist to allow access to camera.