Legacy customization

This page presents a guide to layout customization in the iOS SDKs:

The Storyboard and xibs approach has been discontinued. Please, use the most current way of customization documented on this page.

View Customization

1. Create in your project a framework for view development, using UIViewController, either through the viewCode approach or Storyboards and XIBs.

2. Your interface must contain:

  • A UIView that will display the camera preview in real-time (previewView);

  • A Label for viewing SDK messages ("Center your face", for example);

  • A UIActivityIndicatorView or an element to indicate the loading state;

  • A Label for viewing the name of the step ("Face Register", for example);

  • A Button to close the SDK screen.

3. Link views with the ViewController

4. In the UIViewController, import the SDK

import PassiveFaceLiveness

This guide uses PassiveFaceLiveness as an example, but the logic is replicated for all SDKs.

5. In the viewDidLoad method, instantiate PassiveFaceLiveness and PassiveFaceLivenessCustomViewController. This is where it all happens! :)

 @IBOutlet weak var previewView: UIView!
    var controller: PassiveFaceLivenessCustomViewController!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let passiveFaceLiveness = PassiveFaceLiveness.Builder(mobileToken: "mobileToken")
            // use the builder methods here
            .build()
        
        self.controller = PassiveFaceLivenessCustomViewController(passiveFaceLiveness: passiveFaceLiveness, viewController: self, previewView: previewView)
    }

PassiveFaceLivenessCustomViewController

Parameters

Type

Description

passiveFaceLiveness

PassiveFaceLiveness

Instance created from the builder

viewController

UIViewController

Own class reference

previewView

UIView

UIView which will display the camera preview

6. Overwrite the methods below, making corresponding calls to the PassiveFaceLivenessCustomViewController:

 @override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.controller?.viewWillDisappear()
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.controller?.viewDidAppear()
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        self.controller?.viewDidLayoutSubviews()
    }

7. Use the PassiveFaceLivenessCustomViewDelegate protocol. It will force the implementation of the necessary methods for UI change and SDK response.

lass YourController: UIViewController, PassiveFaceLivenessCustomViewDelegate {

    // MARK: - UI changes

    func show(loading show: Bool) {
        // Use to indicate "loading" state
    }
    
    func show(message text: String) {
        // Present the messages to the user
    }
    
    func show(stepName text: String) {
        // Introduce the name of the step
    }
    
    func show(mask type: MaskType) {
        switch type {
        case .normal:
            // Display the normal state mask
            break
        case .success:
            // Present the mask of success
            break
        case .error:
            // Display the error mask
            break
        default:
            // Display the normal state mask
        }
    }

    // MARK: - SDK Response

    func passiveFaceLivenessController(didFinishWithResults results: PassiveFaceLivenessResult) {
        // Called when the process was successfully executed
        // The result variable contains the obtained data
    }
    
    func passiveFaceLivenessControllerDidCancel() {
       // Called when the process was canceled by the user
    }
    
    func passiveFaceLivenessController(didFailWithError error: PassiveFaceLivenessFailure) {
       // Called when the process ends with an error
       // The error variable contains information about the error
    }
}

8. For the close button, the cancelButtonClick method must be called. This method triggers the delegate passiveFaceLivenessControllerDidCancel:

@IBAction func closeButtonClick(_ sender: Any) {
        self.controller.cancelButtonClick()
    }

9. Finally, call your ViewController and... Voilà, customized view!

Example

We also have a repository on github that contains a customization example, you can access it here.

Last updated

Logo

2023 © Caf. - All rights reserved