Active Passive Liveness Detection

Declaration

func openActivePassiveLivenessDetection(
    on viewController: UIViewController, 
    actions: [LivenessDetectionQuestion]? = nil, 
    doneLaunching: SybrinBiometrics.doneLaunchingType? = nil, 
    success: SybrinBiometrics.activePassiveLivenessDetectionSuccessCallbackType? = nil, 
    failure: SybrinBiometrics.failureCallbackType? = nil, 
    cancel: SybrinBiometrics.cancelCallbackType? = nil
)

To view all the type aliases, go to the SybrinBiometrics class

Handling the doneLaunching , success , failureor cancel callbacks are optional but recommended.

Calling the function

Parameters

Type

Description

UIViewController

The controller you would like to present on.

An array of the questions (or actions) you would like the user to complete during active liveness; all questions are included if nil is passed.

You have to send through the actions/questions as initialised objects. Use the code snippet below as a guide.

let myQuestions: [LivenessDetectionQuestion] = [
    SmileLivenessDetectionQuestion(), 
    BlinkLivenessDetectionQuestion()
]

Then to add the actions when calling active liveness, you can simply pass it as a parameter on the function call, like so:

SybrinBiometrics.shared.openActivePassiveLivenessDetection(
    on: self, 
    actions: myQuestions
)

After executing liveness, the object inside the myQuestions array will be modified and shouldn't be used for another liveness detection function call.

To reuse the same actions/questions for multiple liveness detections, you should initialise the array inline with the function call. Like so:

SybrinBiometrics.shared.openActivePassiveLivenessDetection(
    on: self, 
    actions: [
        SmileLivenessDetectionQuestion(), 
        BlinkLivenessDetectionQuestion()
    ]
)

Handling callback responses

doneLaunching

The doneLaunching callback will be executed after the view controller has successfully launched, or if the view controller failed to launch.

Parameters:

Type

Description

Bool

true if the view controller presented successfully; otherwise, false.

String?

If an error occurs, a message describing the error; otherwise, nil.

Example:

doneLaunching: { (didLaunch, message) in
    if didLaunch {
        print("Launched successfully!")
    } else if let message = message {
        print("Failed to launch because \(message)")
    }
}

success

The success callback will be executed after the session has finished and the view controller has been dismissed.

Parameters:

Type

Description

An object containing the results of the active passive liveness detection session.

Example:

success: { (model) in
    print("Active passive liveness detection finished. You are \(model.isAlive ? "\(model.livenessConfidence * 100)% alive" : "\((1 - model.livenessConfidence) * 100)% not alive")
}

failure

The failure callback will be executed after the session has failed and the view controller has been dismissed.

Parameters:

Type

Description

String

A message describing the error.

If you would like to report a bug, contact us!

Example:

failure: { (message) in
    print("Active passive liveness detection failed because \(message)")
}

cancel

The cancel callback will be executed after the user has dismissed the view controller and before the session could finish.

Parameters:

None

Example:

cancel: {
    print("Active passive liveness detection canceled")
}

Full Example

SybrinBiometrics.shared.openActivePassiveLivenessDetection(
    on: self, 
    actions: [
        SmileLivenessDetectionQuestion(), 
        BlinkLivenessDetectionQuestion()
    ]
) { (didLaunch, message) in
    if didLaunch {
        print("Launched successfully!")
    } else if let message = message {
        print("Failed to launch because \(message)")
    }
} success: { (model) in
    print("Active passive liveness detection finished. You are \(model.isAlive ? "\(model.livenessConfidence * 100)% alive" : "\((1 - model.livenessConfidence) * 100)% not alive")")
} failure: { (message) in
    print("Active passive liveness detection failed because \(message)")
} cancel: {
    print("Active passive liveness detection canceled")
}

Last updated