Skip to content

Liveness

Display Liveness

Liveness Assessment comes with the configuration allowing you to change the behavior and appearance of some UI elements. For more UI customization options, check out the UI Customization section.

Starting the Liveness process with configuration:

let configuration = LivenessConfiguration { _ in

}

FaceSDK.service.startLiveness(
    from: viewController,
    animated: true, 
    configuration: configuration,
    onLiveness: { response in
        // ... check response.liveness for detection result.
    },
    completion: nil
)
RFSLivenessConfiguration *configuration = [RFSLivenessConfiguration configurationWithBuilder:^(RFSLivenessConfigurationBuilder  * _Nonnull builder) {

}];

[RFSFaceSDK.service startLivenessFrom:viewController
                             animated:YES
                        configuration:configuration
                           onLiveness:^(RFSLivenessResponse * _Nonnull response) {
    // ... check response.liveness for detection result.
} completion:nil];
val configuration = LivenessConfiguration.Builder()
    .build()

FaceSDK.Instance().startLiveness(this@MainActivity, configuration) { response ->
    // ... check response.getLiveness(); for detection result.
}
LivenessConfiguration configuration = new LivenessConfiguration.Builder()
    .build();

FaceSDK.Instance().startLiveness(MainActivity.this, configuration, livenessResponse -> {
    // ... check livenessResponse.liveness for detection result.
});
FaceSDK.startLiveness(livenessResponse => {
    const response = LivenessResponse.fromJson(JSON.parse(livenessResponse));
    // ... check response.liveness for detection result.
}, e => { });
FaceSDK.startLiveness().then((livenessResponse) {
    var response = LivenessResponse.fromJson(jsonDecode(livenessResponse));
    // ... check response.liveness for detection result.
});
FaceSDK.startLiveness(livenessResponse => {
    const response = FaceSDK.LivenessResponse.fromJson(JSON.parse(livenessResponse));
    // ... check response.liveness for detection result.
}, e => { });
FaceSDK.startLiveness().then(livenessResponse => {
    const response = LivenessResponse.fromJson(JSON.parse(livenessResponse));
    // ... check response.liveness for detection result.
});

To keep the default configuration, you can omit the configuration parameter.

To stop the Liveness processing programmatically, there is a call:

FaceSDK.service.stopLivenessProcessing()
[RFSFaceSDK.service stopLivenessProcessing];
FaceSDK.Instance().stopLivenessProcessing(this@MainActivity)
FaceSDK.Instance().stopLivenessProcessing(MainActivity.this);
FaceSDK.stopLivenessProcessing(() => {}, () => {});
FaceSDK.stopLivenessProcessing();
FaceSDK.stopLivenessProcessing();
FaceSDK.stopLivenessProcessing();

Tag

The detailed tag description is available on the Feature Introduction page.

To set up tag, invoke:

let configuration = LivenessConfiguration { 
    $0.tag = UUID().uuidString
}

FaceSDK.service.startLiveness(
    from: viewController,
    animated: true, 
    configuration: configuration,
    onLiveness: { response in

    },
    completion: nil
)
RFSLivenessConfiguration *configuration = [RFSLivenessConfiguration configurationWithBuilder:^(RFSLivenessConfigurationBuilder  * _Nonnull builder) {
    builder.tag = [[NSUUID UUID] UUIDString];
}];

[RFSFaceSDK.service startLivenessFrom:viewController
                             animated:YES
                        configuration:configuration
                           onLiveness:^(RFSLivenessResponse * _Nonnull response) {

} completion:nil];
val configuration = LivenessConfiguration.Builder()
            .setTag(UUID.randomUUID().toString())
            .build()
FaceSDK.Instance().startLiveness(context, configuration) { livenessResponse: LivenessResponse? -> }
LivenessConfiguration configuration = new LivenessConfiguration.Builder()
            .setTag(UUID.randomUUID().toString())
            .build();
FaceSDK.Instance().startLiveness(context, configuration, livenessResponse -> {});
FaceSDK.startLivenessWithConfig({
  tag: ""
}, _ => { }, _ => { });
FaceSDK.startLivenessWithConfig({
  "tag": "",
});
FaceSDK.startLivenessWithConfig({
  tag: ""
}, function (m) { }, function (e) { });
FaceSDK.startLivenessWithConfig({
  tag: ""
});

For details about the status of the session video upload to the service, see Session Video Upload Status.

Response

Status

LivenessResponse contains the response.json file, where you can find livenessStatus with the result of processing: 0 if the person's liveness is confirmed, 1 if not. Also, the errors may be returned.

To determine the result of the detection, check for the liveness property:

if case response.liveness = .passed {
    // continue with successful path.
}
if (response.liveness == RFSLivenessStatusPassed) {
    // continue with successful path.
}
Log.d("liveness", "Session id: " + response.tag)
Log.d("liveness", "Transaction id: " + response.transactionId)
Log.d("liveness", "Session id: " + response.getTag());
Log.d("liveness", "Transaction id: " + response.getTransactionId());
if (response.liveness == LivenessStatus.PASSED) {
    // continue with successful path.
}
if (response?.liveness == LivenessStatus.PASSED) {
    // continue with successful path.
}
if (response.liveness == FaceSDK.Enum.LivenessStatus.PASSED) {
    // continue with successful path.
}
if (response.liveness == LivenessStatus.PASSED) {
    // continue with successful path.
}

UI Customization

A number of UI elements of the liveness assessment session can be customized to suit your application's unique requirements. See the Liveness Assessment Session UI Customization for details.

To add text and graphic elements to the camera UI, follow the guides:

Error Handling

The errors and exceptions give you an insight into what happened to the Liveness processing from a user canceling the operation to a missing license on a web service.

Here is an example of how you can handle a failed LivenessResponse:

if let error = response.error {
    // There is an error. Lets see what type is it.
    switch error {
        case LivenessError.cancelled:
            Log.d("User cancelled the processing.")
        case LivenessError.noLicense:
            Log.d("Web Service is missing a valid License.")
        case LivenessError.processingAttemptsEnded:
            Log.d("Reached the number of possible attempts. See `RFSLivenessConfiguration.attemptsCount` for more information.")
        case LivenessError.processingFailed:
            Log.d("Bad input data.")
        case LivenessError.processingTimeout:
            Log.d("Processing finished by timeout.")
        case LivenessError.apiCallFailed:
            Log.d("Web Service API call failed due to networking error or backend internal error.")
        default:
            break
    }
}
if (response.error) {
    // There is an error. Lets see what type is it.
    switch ((RFSLivenessError)response.error.code) {
        case RFSLivenessErrorCancelled:
            NSLog(@"User cancelled the processing.");
            break;
        case RFSLivenessErrorNoLicense:
            NSLog(@"Web Service is missing a valid License.");
            break;
        case RFSLivenessErrorProcessingAttemptsEnded:
            NSLog(@"Reached the number of possible attempts. See `RFSLivenessConfiguration.attemptsCount` for more information.");
            break;
        case RFSLivenessErrorProcessingFailed:
            NSLog(@"Bad input data.");
            break;
        case RFSLivenessErrorProcessingTimeout:
            NSLog(@"Processing finished by timeout.");
            break;
        case RFSLivenessErrorAPICallFailed:
            NSLog(@"Web Service API call failed due to networking error or backend internal error.");
            break;
    }
}
val exception = response.exception
if (exception != null) {
    when (exception.errorCode) {
        LivenessErrorCode.CANCELLED ->
            Log.d("User cancelled the processing.")
        LivenessErrorCode.NO_LICENSE ->
            Log.d("Web Service is missing a valid License.")
        LivenessErrorCode.PROCESSING_ATTEMPTS_ENDED ->
            Log.d("Reached the number of possible attempts. See `LivenessConfiguration.attemptsCount` for more information.")
        LivenessErrorCode.PROCESSING_FAILED ->
            Log.d("Bad input data.")
        LivenessErrorCode.PROCESSING_TIMEOUT ->
            Log.d("Processing finished by timeout.")
        LivenessErrorCode.API_CALL_FAILED ->
            Log.d("Web Service API call failed due to networking error or backend internal error.")
        LivenessErrorCode.CONTEXT_IS_NULL ->
            Log.d("Provided context is null.")
        LivenessErrorCode.IN_PROGRESS_ALREADY ->
            Log.d("Liveness has already started.")
        LivenessErrorCode.ZOOM_NOT_SUPPORTED ->
            Log.d("Camera zoom support is required.")
        LivenessErrorCode.CAMERA_NO_PERMISSION ->
            Log.d("Application does not have camera permission.")
        LivenessErrorCode.CAMERA_NOT_AVAILABLE ->
            Log.d("Device has no available camera.")
        LivenessErrorCode.PROCESSING_FRAME_FAILED ->
            Log.d("Failed when Core could not recognize frame.")
    }
}
LivenessErrorException exception = response.getException();
if (exception != null) {
    switch (exeption.getErrorCode()) {
        case LivenessErrorCode.CANCELLED:
            Log.d("liveness", "User cancelled the processing.");
            break;
        case LivenessErrorCode.NO_LICENSE:
            Log.d("liveness", "Web Service is missing a valid License.");
            break;
        case LivenessErrorCode.PROCESSING_ATTEMPTS_ENDED:
            Log.d("liveness", "Reached the number of possible attempts. See `LivenessConfiguration.attemptsCount` for more information.");
            break;
        case LivenessErrorCode.PROCESSING_FAILED:
            Log.d("liveness", "Bad input data.");
            break;
        case LivenessErrorCode.PROCESSING_TIMEOUT:
            Log.d("liveness", "Processing finished by timeout.");
            break;
        case LivenessErrorCode.API_CALL_FAILED:
            Log.d("liveness", "Web Service API call failed due to networking error or backend internal error.");
            break;
        case LivenessErrorCode.CONTEXT_IS_NULL:
            Log.d("liveness", "Provided context is null.");
            break;
        case LivenessErrorCode.IN_PROGRESS_ALREADY:
            Log.d("liveness", "Liveness has already started.");
            break;
        case LivenessErrorCode.ZOOM_NOT_SUPPORTED:
            Log.d("liveness", "Camera zoom support is required.");
            break;
        case LivenessErrorCode.CAMERA_NO_PERMISSION:
            Log.d("liveness", "Application does not have camera permission.");
            break;
        case LivenessErrorCode.CAMERA_NOT_AVAILABLE:
            Log.d("liveness", "Device has no available camera.");
            break;
        case LivenessErrorCode.PROCESSING_FRAME_FAILED:
            Log.d("liveness", "Failed when Core could not recognize frame.");
            break;
    }
}
const exception = response.exception;
if (exception) {
    switch (exception.errorCode) {
        case LivenessErrorCode.CANCELLED:
            console.log('liveness: User cancelled the processing.');
            break;
        case LivenessErrorCode.NO_LICENSE:
            console.log('liveness: Web Service is missing a valid License.');
            break;
        case LivenessErrorCode.PROCESSING_ATTEMPTS_ENDED:
            console.log('liveness: Reached the number of possible attempts. See `LivenessConfiguration.attemptsCount` for more information.');
            break;
        case LivenessErrorCode.PROCESSING_FAILED:
            console.log('liveness: Bad input data.');
            break;
        case LivenessErrorCode.PROCESSING_TIMEOUT:
            console.log('liveness: Processing finished by timeout.');
            break;
        case LivenessErrorCode.API_CALL_FAILED:
            console.log('liveness: Web Service API call failed due to networking error or backend internal error.');
            break;
        case LivenessErrorCode.CONTEXT_IS_NULL:
            console.log('liveness: Provided context is null.');
            break;
        case LivenessErrorCode.IN_PROGRESS_ALREADY:
            console.log('liveness: Liveness has already started.');
            break;
        case LivenessErrorCode.ZOOM_NOT_SUPPORTED:
            console.log('liveness: Camera zoom support is required.');
            break;
    }
}
var exception = response?.exception;
if (exception != null) {
  switch (exception.errorCode) {
    case LivenessErrorCode.CANCELLED:
      print('liveness: User cancelled the processing.');
      break;
    case LivenessErrorCode.NO_LICENSE:
      print('liveness: Web Service is missing a valid License.');
      break;
    case LivenessErrorCode.PROCESSING_ATTEMPTS_ENDED:
      print('liveness: Reached the number of possible attempts. See `LivenessConfiguration.attemptsCount` for more information.');
      break;
    case LivenessErrorCode.PROCESSING_FAILED:
      print('liveness: Bad input data.');
      break;
    case LivenessErrorCode.PROCESSING_TIMEOUT:
      print('liveness: Processing finished by timeout.');
      break;
    case LivenessErrorCode.API_CALL_FAILED:
      print(
          'liveness: Web Service API call failed due to networking error or backend internal error.');
      break;
    case LivenessErrorCode.CONTEXT_IS_NULL:
      print('liveness: Provided context is null.');
      break;
    case LivenessErrorCode.IN_PROGRESS_ALREADY:
      print('liveness: Liveness has already started.');
      break;
    case LivenessErrorCode.ZOOM_NOT_SUPPORTED:
      print('liveness: Camera zoom support is required.');
      break;
  }
}
const exception = response.exception;
if (exception) {
    switch (exception.errorCode) {
        case FaceSDK.Enum.LivenessErrorCode.CANCELLED:
            console.log('liveness: User cancelled the processing.');
            break;
        case FaceSDK.Enum.LivenessErrorCode.NO_LICENSE:
            console.log('liveness: Web Service is missing a valid License.');
            break;
        case FaceSDK.Enum.LivenessErrorCode.PROCESSING_ATTEMPTS_ENDED:
            console.log('liveness: Reached the number of possible attempts. See `LivenessConfiguration.attemptsCount` for more information.');
            break;
        case FaceSDK.Enum.LivenessErrorCode.PROCESSING_FAILED:
            console.log('liveness: Bad input data.');
            break;
        case FaceSDK.Enum.LivenessErrorCode.PROCESSING_TIMEOUT:
            console.log('liveness: Processing finished by timeout.');
            break;
        case FaceSDK.Enum.LivenessErrorCode.API_CALL_FAILED:
            console.log('liveness: Web Service API call failed due to networking error or backend internal error.');
            break;
        case FaceSDK.Enum.LivenessErrorCode.CONTEXT_IS_NULL:
            console.log('liveness: Provided context is null.');
            break;
        case FaceSDK.Enum.LivenessErrorCode.IN_PROGRESS_ALREADY:
            console.log('liveness: Liveness has already started.');
            break;
        case FaceSDK.Enum.LivenessErrorCode.ZOOM_NOT_SUPPORTED:
            console.log('liveness: Camera zoom support is required.');
            break;
    }
}
const exception = response.exception;
if (exception) {
    switch (exception.errorCode) {
        case LivenessErrorCode.CANCELLED:
            console.log('liveness: User cancelled the processing.');
            break;
        case LivenessErrorCode.NO_LICENSE:
            console.log('liveness: Web Service is missing a valid License.');
            break;
        case LivenessErrorCode.PROCESSING_ATTEMPTS_ENDED:
            console.log('liveness: Reached the number of possible attempts. See `LivenessConfiguration.attemptsCount` for more information.');
            break;
        case LivenessErrorCode.PROCESSING_FAILED:
            console.log('liveness: Bad input data.');
            break;
        case LivenessErrorCode.PROCESSING_TIMEOUT:
            console.log('liveness: Processing finished by timeout.');
            break;
        case LivenessErrorCode.API_CALL_FAILED:
            console.log('liveness: Web Service API call failed due to networking error or backend internal error.');
            break;
        case LivenessErrorCode.CONTEXT_IS_NULL:
            console.log('liveness: Provided context is null.');
            break;
        case LivenessErrorCode.IN_PROGRESS_ALREADY:
            console.log('liveness: Liveness has already started.');
            break;
        case LivenessErrorCode.ZOOM_NOT_SUPPORTED:
            console.log('liveness: Camera zoom support is required.');
            break;
    }
}

Info

For more information about LivenessConfiguration and LivenessResponse, see the SDK Reference page.