Skip to content

Face Capture

Face Capture is a UI module that displays the Camera UI and automatically captures a photo with a person's face on it.

Face Capture comes with a configuration allowing you to change the behavior and appearance of some UI elements. For more UI customization, please check out UI Customization.

Show the Face Capture module with configuration:

let configuration = FaceCaptureConfiguration {
    $0.cameraPosition = .front
    $0.cameraSwitchEnabled = true
}

FaceSDK.service.presentFaceCaptureViewController(
    from: viewController,
    animated: true, 
    configuration: configuration,
    onCapture: { response in
        // ... check response.image for capture result.
    },
    completion: nil
)
RFSFaceCaptureConfiguration *configuration = [RFSFaceCaptureConfiguration configurationWithBuilder:^(RFSFaceCaptureConfigurationBuilder * _Nonnull builder) {
builder.cameraPosition = RFSCameraPositionFront;
builder.cameraSwitchEnabled = YES;
}];

[RFSFaceSDK.service presentFaceCaptureViewControllerFrom:viewController
                                                animated:YES
                                        configuration:configuration
                                            onCapture:^(RFSFaceCaptureResponse * _Nonnull response) {
// ... check response.image for capture result.
} completion:nil];
val configuration = FaceCaptureConfiguration.Builder()
    .setCameraId(0)
    .setCameraSwitchEnabled(true)
    .build()

FaceSDK.Instance().presentFaceCaptureActivity(this@MainActivity, configuration) { response ->
    // ... check response.image for capture result.
}
FaceCaptureConfiguration configuration = new FaceCaptureConfiguration.Builder()
    .setCameraId(0)
    .setCameraSwitchEnabled(true)
    .build();

FaceSDK.Instance().presentFaceCaptureActivity(MainActivity.this, configuration, response -> {
    // ... check response.getImage(); for capture result.
});
FaceSDK.startFaceCapture({
  cameraPositionAndroid: 0,
  cameraPositionIOS: Enum.CameraPosition.FRONT,
  cameraSwitchEnabled: true
}, (json) => {
  var response = FaceCaptureResponse.fromJson(JSON.parse(json))
  // ... check response.image.image for capture result.
}, _ => { })
var response = await FaceSDK.instance.startFaceCapture(
  config: FaceCaptureConfig(
    cameraPositionAndroid: 0,
    cameraPositionIOS: CameraPosition.FRONT,
    cameraSwitchEnabled: true,
  ),
);
// ... check response.image.image for capture result.
FaceSDK.startFaceCapture({
    cameraPositionAndroid: 0,
    cameraPositionIOS: Enum.CameraPosition.FRONT,
    cameraSwitchEnabled: true
}, raw => {
    // handling events:
    var csEventId = "cameraSwitchEvent"
    if (raw.substring(0, csEventId.length) === csEventId) {
        raw = raw.substring(csEventId.length, raw.length)
        var cameraId = raw
        // handle new camera id
    } else {
        var response = FaceCaptureResponse.fromJson(JSON.parse(raw))
        // ... check response.image.image for capture result.
    }
}, e => { })
FaceSDK.startFaceCapture({
  cameraPositionAndroid: 0,
  cameraPositionIOS: Enum.CameraPosition.FRONT,
  cameraSwitchEnabled: true
}).subscribe((raw: string) => {
  // handling events:
  var csEventId = "cameraSwitchEvent"
  if (raw.substring(0, csEventId.length) === csEventId) {
    raw = raw.substring(csEventId.length, raw.length)
    var cameraId = raw
    // handle new camera id
  } else {
    var response = FaceCaptureResponse.fromJson(JSON.parse(raw))
    // ... check response.image.image for capture result.
  }
})
// Android
FaceCaptureConfiguration configuration = new FaceCaptureConfiguration.Builder()
    .SetCameraId(0)
    .SetCameraSwitchEnabled(true)
    .Build();
FaceSDK.Instance().PresentFaceCaptureActivity(Platform.AppContext, configuration, this);

// iOS
RFSFaceSDK.Service.PresentFaceCaptureViewControllerFrom(CurrentPresenter, true, RFSFaceCaptureConfiguration.ConfigurationWithBuilder((RFSFaceCaptureConfigurationBuilder builder) =>
{
    builder.CameraPosition = RFSCameraPosition.Front;
    builder.CameraSwitchButtonEnabled = true;
}),
(RFSFaceCaptureResponse response) =>
{
    // ... check response.image for capture result.
}, null);

To keep the default configuration, omit the configuration parameter.

Info

For more information on FaceCaptureConfiguration and FaceCaptureResponse, please see SDK Reference.