Biometric Capture
Implementing the Biometric Capture Session in a View-based UI
This example shows how to integrate the Biometric Capture Session into your project. The Biometric Capture Session extracts a frame collection from the camera preview.
Add the Capture Session .xcframework inside the project. Link to guide on how to integrate the library inside the project https://www.simpleswiftguide.com/how-to-add-xcframework-to-xcode-project
Create View inside ViewController.
After finishing the import of .xcframework inside the project, you can import the library inside the swift file.
import MobaiBiometric
In the UI for this example app, we use the following:
Create view
private var mbCaptureSessionView: MBCaptureSessionView
Initialisation view with MBCaptureSessionOptions
public init() {
self.options = MBCaptureSessionOptions()
self.mbCaptureSessionView = MBCaptureSessionView(options: self.options)
}
Setup View Constraints
view.addSubview(takePictureButton)
NSLayoutConstraint.activate([
mbCaptureSessionView.topAnchor.constraint(equalTo: view.topAnchor),
mbCaptureSessionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
mbCaptureSessionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
mbCaptureSessionView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
Starts Camera if camera permissions are granted
public override func viewWillAppear(_ animated: Bool) {
mbCaptureSessionView.onStartCapturing()
}
Stop Capturing
public override func viewWillDisappear(_ animated: Bool) {
mbCaptureSessionView.onStopCapturing()
}
Adding delegate and implementing the delegate inside View Controller
mbCaptureSessionView.captureSessionDelegate = self
mbCaptureSessionView.countDownDelegate = self
mbCaptureSessionView.validatingDelegate = self
mbCaptureSessionView.progressDelegate = self
extension ExampleViewController: MBCaptureSessionDelegate, MBOnValidatingDelegate, MBCountDownDelegate, MBCaptureProgressDelegate { }
Delegate
MBCaptureSessionDelegate
MBCaptureSessionDelegate is executed for MBCaptureSession when the capture session is finished or aborted
onSuccess is executed for MBCaptureSession class when the capture session is successfully finished
@param result contains a list of frames.
func onSuccess(result: MBCaptureSessionResult)
onFailure is executed for MBCaptureSessionService class when the camera can not be
@param error describes whether there is a camera or face failure
func onFailure(error: MBCaptureSessionError)
onStateChanged is executed when the state is changes
@param stateEnum is status enum of the state changed like onInitializing, validating, countdown, onCaptureStarted, onProcessing, onCaptureFinished
func onStateChanged(captureState: MBCaptureState)
MBCountDownDelegate
MBCountDownDelegate listen for the count down new values
onCountdown
is executed in every timer engine iteration
@param timeCounter is the current time in seconds.
func onCountDown(timeCounter: Int)
MBOnValidatingDelegate
MBOnValidatingDelegate is executed when the status of the face changes
@param faceStatus describes the face location on the camera preview.
func onValidating(_ faceStatus: DetectedFaceStatus)
MBCaptureProgressDelegate
onCaptureProgress is executed every time the valid frames collecting is progressing.
@param captureProgressCounter represent the value from 0 to 1 of the collecting frames progress.
func onCaptureProgress(captureProgressCounter: Float)
Calling ViewController.
Initialization and calling present of MBCaptureSessionViewController
let viewController = MBCaptureSessionViewController(options: .init())
viewController.delegate = self
self.present(viewController, animated: true, completion: nil)
Delegate
MBCaptureSessionVCDelegate
onSuccess is executed for MBCaptureSession class when the capture session is successfully finished
@param result contains a list of frames.
func onSuccess(result: MBCaptureSessionResult) { }
onFailure is executed for MBCaptureSessionService class when the camera can not be
@param error describes whether there is a camera or face failure
func onFailure(error: MBCaptureSessionError) { }
onStateChanged is executed when the state is changes
@param stateEnum is status enum of the state changed like onInitializing, validating, countdown, onCaptureStarted, onProcessing, onCaptureFinished
func onStateChanged(stateEnum: MBCaptureState)
onPresentedDismissTapped is executed when the user close the screen from the X button
func onPresentedDismissTapped() { }
Options
MBCaptureSessionOptions
Inside the library, we have some options for changing the behaviour of capturing data:
Variable Name | Type | Default Value |
---|---|---|
autoCaptureEnabled | boolean | true |
numberOfFrameToCollect | number | 3 |
timeBeforeAutomaticCapture | number | 1 |
cameraQuality | MBCameraOptions | MBCameraOptions() |
isDebugging | boolean | false |
payloadOptimization | boolean | false |
autoCaptureEnabled
- tells whether the capture is automatic or manual:
- Automatic: Automatically take an image with a specific time that you can configure with timeBeforeAutomaticCapture
- Manual: Manually take an image with the help of a button that the library shows
- tells whether the capture is automatic or manual:
numberOfFrameToCollect
- describes the number of frames to collect during the capture session.
timeBeforeAutomaticCapture
- number of seconds that the user needs to wait in automatic capture
faceQualityEnabled
- to capture an image in a higher resolution
cameraQuality
- set the options for the camera.
isDebugging
- If it is set to false will just display the overlay on the top of the camera. If it is set to true will display all components available ont the top of the camera(timer text, progress bar and face status text).
payloadOptimization
- used to enable or disable optimization of the payload size generated by the capture session.
MBCameraOptions
Variable Name | Type | Default Value |
---|---|---|
targetResolution | MBTargetResolution | .hd1280x720 |
previewScaleType | MBPreviewScaleType | .fit |
cameraPosition | MBCameraPostion | .front |
targetResolution
- option to change the resolution of the camera
- hd1280x720(default option)
- hd1920x1080
- hd4K3840x2160
- qHD960x540
- option to change the resolution of the camera
previewScaleType
- Fill: Resize the video preview to fill the layer and keep the aspect ratio
- Fit: Resize the video preview to fit inside the layer and keep the aspect ratio
cameraPosition
- option to select the side of the camera|
- Front
- Back
- option to select the side of the camera|
MBUIOptions
Variable Name | Type | Default Value |
---|---|---|
showProgressBar | boolean | false |
showFaceStatusLabel | boolean | false |
showCountdownTimerLabel | boolean | false |
presentedDismissButtonEnabled | boolean | false |
textLocalizations | MBTextLocalizations | .init() |
showProgressBar
- Is used to show or hide the progress bar. The progress bar indicates to the user how far in the capture process we are.
showFaceStatusLabel
- Is used to show or hide the face status label. The face status label is used to indicate to the user if the face is in the correct position or not.
showCountdownTimerLabel
- Is used to show or hide the label displayed during countdown before capture starts.
The text for the countdownLabel can be set using the
countdownLabelText
option.
- Is used to show or hide the label displayed during countdown before capture starts.
The text for the countdownLabel can be set using the
presentedDismissButtonEnabled
- Option to add or remove the dismiss button at the top (This works only with the ViewController approach)
textLocalizations
- Describe the text that is displayed on the top of the camera.
MBTextLocalizations
Variable Name | Type | Default Value |
---|---|---|
countdownLabelText | string | 'Hold Still' |
faceStatusTexts | MBFaceStatusTexts | MBFaceStatusTexts() |
cameraPermissionAlert | MBCameraPermissionAlert | MBCameraPermissionAlert() |
countdownLabelText
- Is used to customize the text shown in the countdown label
faceStatusTexts
- Is used to customize or localize the text displayed to the user indicating if the face is in correct position or not.
If no input is provided to
faceStatusTexts
default values are used.
- Is used to customize or localize the text displayed to the user indicating if the face is in correct position or not.
If no input is provided to
cameraPermissionAlert
- Is the Alert that show to user when is requiring permissions
MBFaceStatusTexts
Is object to customize or localize the text displayed to the user indicating if the face is in correct position or not.
If no input is provided to faceStatusTexts
default values are used.
Variable Name | Type | Default Value |
---|---|---|
faceTooFarAway | string | 'Face too far away' |
faceTooFarUp | string | 'Face too far up' |
faceTooFarDown | string | 'Face too far down' |
faceTooFarLeft | string | 'Face too far left' |
faceTooFarRight | string | 'Face too far right' |
faceTooClose | string | 'Face too close' |
faceNotFound | string | 'Face not found' |
tooManyFaces | string | 'Too many faces' |
validFace | string | 'Valid faceaway' |
MBCameraPermissionAlert
Is object to customize text of Alert that show to user when is requiring permissions
Variable Name | Type | Default Value |
---|---|---|
title | string | 'To continue the app need access for settings!' |
message | string | 'Go to Settings?' |
settingText | string | 'Settings' |
cancelText | string | 'Cancel' |
If you have any questions, please contact .....