2.0.0 Upgrade Guide
This page shows an overview of the changes between the previous version and 2.0.0
Changes to configuration options
The options have been grouped in separate models.
- 2.0.0
- 2.0.0-beta.19
//Implementing Options for the View
var cameraOptions = MBCameraOptions(
targetResolution: .hd1280x720,
previewScaleType: .fit,
cameraPosition: .front
)
var options = MBCaptureSessionOptions(
autoCaptureEnabled: true,
numberOfFrameToCollect: 3,
timeBeforeAutomaticCapture: 4,
isDebugging: false,
payloadOptimization: false,
cameraQuality: cameraOptions
)
self.mbCaptureSessionView = MBCaptureSessionView(options: options)
// Implementing Options for the View Controller
var cameraOptions = MBCameraOptions(
targetResolution: .hd1280x720,
previewScaleType: .fit,
cameraPosition: .front
)
var options = MBCaptureSessionOptions(
autoCaptureEnabled: true,
numberOfFrameToCollect: 3,
timeBeforeAutomaticCapture: 4,
isDebugging: false,
payloadOptimization: false,
cameraQuality: cameraOptions
)
var cameraPermissions = MBCameraPermissionAlert(
title: "To continue the app need access for settings!",
message: "Go to Settings?",
settingText: "Settings",
cancelText: "Cancel"
)
var faceStatusTexts = MBFaceStatusTexts(
faceTooFarAway: "Face too far away",
faceTooFarUp: "Face too far up",
faceTooFarDown: "Face too far down",
faceTooFarLeft: "Face too far left",
faceTooFarRight: "Face too far right",
faceTooClose: "Face too close",
faceNotFound: "Face not found",
tooManyFaces: "Too many faces",
validFace: "Valid face"
)
var textLocalizations = MBTextLocalizations(
countdownLabelText: "Hold Still",
faceStatusTexts: faceStatusTexts,
cameraPermissionAlert: cameraPermissions
)
var style = MBUIOptions(
showProgressBar: false,
showFaceStatusLabel: false,
showCountdownTimerLabel: false,
presentedDismissButtonEnabled: false,
textLocalizations: textLocalizations
)
self.viewContoller = MBCaptureSessionViewController(with: options, style: style)
// Implementing Options for the View
var cameraPermissionAlert = CameraPermissionAlert(
title: "To continue the app need access for settings!",
message: "Go to Settings?",
settingText: "Settings",
cancelText: "Cancel"
)
var faceStatus = MBFaceStatusTexts(
faceTooFarAway: "Face too far away",
faceTooFarUp: "Face too far up",
faceTooFarDown: "Face too far down",
faceTooFarLeft: "Face too far left",
faceTooFarRight: "Face too far right",
faceTooClose: "Face too close",
faceNotFound: "Face not found",
tooManyFaces: "Too many faces",
validFace: "Valid face"
)
var options = MBCaptureSessionOptions(
autoCaptureEnabled: true,
numberOfFramesBeforeCapture: 0,
numberOfFrameToCollect: 3,
frameInterval: 10,
faceQualityEnabled: false,
isDebugging: false,
timeBeforeAutomaticCapture: 1,
cameraPosition: .front,
presentedDismissButtonEnabled: false,
targetResolutionPad: .hd1280x720,
previewScaleType: .fit,
cameraPermissionAlert: cameraPermissionAlert,
faceStatusTexts: faceStatus,
showCountdownTimerLabel: false,
showProgressBar: false,
showFaceStatusLabel: false,
countdownLabelText: "Hold Still",
payloadOptimization: false
)
self.mbCaptureSessionView = MBCaptureSessionView(options: options)
// Implementing Options for the View Controller
var cameraPermissionAlert = CameraPermissionAlert(
title: "To continue the app need access for settings!",
message: "Go to Settings?",
settingText: "Settings",
cancelText: "Cancel"
)
var faceStatus = MBFaceStatusTexts(
faceTooFarAway: "Face too far away",
faceTooFarUp: "Face too far up",
faceTooFarDown: "Face too far down",
faceTooFarLeft: "Face too far left",
faceTooFarRight: "Face too far right",
faceTooClose: "Face too close",
faceNotFound: "Face not found",
tooManyFaces: "Too many faces",
validFace: "Valid face"
)
var options = MBCaptureSessionOptions(
autoCaptureEnabled: true,
numberOfFramesBeforeCapture: 0,
numberOfFrameToCollect: 3,
frameInterval: 10,
faceQualityEnabled: false,
isDebugging: false,
timeBeforeAutomaticCapture: 1,
cameraPosition: .front,
presentedDismissButtonEnabled: false,
targetResolutionPad: .hd1280x720,
previewScaleType: .fit,
cameraPermissionAlert: cameraPermissionAlert,
faceStatusTexts: faceStatus,
showCountdownTimerLabel: false,
showProgressBar: false,
showFaceStatusLabel: false,
countdownLabelText: "Hold Still",
payloadOptimization: false
)
self.viewContoller = MBCaptureSessionViewController(options: options)
Changes to delegates for callbacks and events
The delegates have been divided into separate interfaces in order to facilitate more customization and expanding functionality.
- 2.0.0
- 2.0.0-beta.19
//Implementing View
public protocol MBCaptureSessionDelegate {
/**
Called when the capture session finishes successfully.
- Parameters:
- result: The result of the capture session that includes the captured data.
*/
func onSuccess(result: MBCaptureSessionResult)
/**
Called when the capture session encounters an error.
- Parameters:
- error: An enumeration representing the specific error that occurred.
*/
func onFailure(error: MBCaptureSessionError)
/**
Called when the capture session changes state.
- Parameters:
- stateEnum: An enumeration representing the current state of the capture session
*/
func onStateChanged(captureState: MBCaptureState)
}
public protocol MBOnValidatingDelegate {
/**
Called everytime a camera frame is processed during the validation stage of the capture process.
- Parameters:
- faceStatus: An object describing if the face is valid with regards to the constraints
set for the face capture process.
*/
func onValidating(_ faceStatus: MBFaceStatus)
}
public protocol MBCountDownDelegate {
/**
Called every second while the countdown is active
- Parameters:
- timeCounter: The current time remaining in seconds.
*/
func onCountDown(timeCounter: Int)
}
public protocol MBCaptureProgressDelegate {
/**
Called to provide updates on the progress of the capture process
- Parameters:
- captureProgressCounter: A float value indicating the current progress of the capture process. The value is in the range [0.0, 1.0]
*/
func onCaptureProgress(captureProgressCounter: Float)
}
//Implementing ViewController
public protocol MBCaptureSessionVCDelegate {
/**
Called when the capture session finishes successfully.
- Parameters:
- result: The result of the capture session that includes the captured data.
*/
func onSuccess(result: MBCaptureSessionResult)
/**
Called when the capture session encounters an error.
- Parameters:
- error: An enumeration representing the specific error that occurred.
*/
func onFailure(error: MBCaptureSessionError)
/**
Called when the capture session changes state.
- Parameters:
- stateEnum: An enumeration representing the current state of the capture session
*/
func onStateChanged(stateEnum: MBCaptureState)
/**
Called when the view controller is dismissed using the on screen dismiss button.
*/
func onPresentedDismissTapped()
}
// Implementing View
public protocol MBCaptureSessionDelegate {
func onInitializing()
func onCaptureStarted()
func onCaptureFinished(result: MBCaptureSessionResult)
func onValidating(_ faceStatus: DetectedFaceStatus)
func onCountDown(time: Int)
func onCaptureProgress(captureProgressCounter: Float)
func onFailure(error: MBCaptureSessionError)
}
// Implementing View Controller
public protocol MBCaptureSessionVCDelegate {
func onSuccess(result: MBCaptureSessionResult)
func onFailure(error: MBCaptureSessionError)
func onPresentedDismissTapped()
}
Example Implementation
- 2.0.0
- 2.0.0-beta.19
// Implementing View
class ExampleViewController: MBCaptureSessionDelegate, MBOnValidatingDelegate, MBCountDownDelegate, MBCaptureProgressDelegate {
private let mbCaptureSessionView: MBCaptureSessionView
public init() {
var cameraOptions = MBCameraOptions(
targetResolution: .hd1280x720,
previewScaleType: .fit,
cameraPosition: .front
)
var options = MBCaptureSessionOptions(
autoCaptureEnabled: true,
numberOfFrameToCollect: 3,
timeBeforeAutomaticCapture: 4,
isDebugging: false,
payloadOptimization: false,
cameraQuality: cameraOptions
)
self.mbCaptureSessionView = MBCaptureSessionView(options: options)
}
func onSuccess(result: MBCaptureSessionResult) { }
func onFailure(error: MBCaptureSessionError) { }
func onStateChanged(captureState: MBCaptureState) { }
func onValidating(_ faceStatus: DetectedFaceStatus) { }
func onCountDown(timeCounter: Int) { }
func onCaptureProgress(captureProgressCounter: Float) { }
}
// Implementing View Controller
class ExampleViewController: UIViewController, MBCaptureSessionVCDelegate {
var viewContoller: MBCaptureSessionViewController
init() {
var cameraOptions = MBCameraOptions(
targetResolution: .hd1280x720,
previewScaleType: .fit,
cameraPosition: .front
)
var options = MBCaptureSessionOptions(
autoCaptureEnabled: true,
numberOfFrameToCollect: 3,
timeBeforeAutomaticCapture: 4,
isDebugging: false,
payloadOptimization: false,
cameraQuality: cameraOptions
)
var cameraPermissions = MBCameraPermissionAlert(
title: "To continue the app need access for settings!",
message: "Go to Settings?",
settingText: "Settings",
cancelText: "Cancel"
)
var faceStatusTexts = MBFaceStatusTexts(
faceTooFarAway: "Face too far away",
faceTooFarUp: "Face too far up",
faceTooFarDown: "Face too far down",
faceTooFarLeft: "Face too far left",
faceTooFarRight: "Face too far right",
faceTooClose: "Face too close",
faceNotFound: "Face not found",
tooManyFaces: "Too many faces",
validFace: "Valid face"
)
var textLocalizations = MBTextLocalizations(
countdownLabelText: "Hold Still",
faceStatusTexts: faceStatusTexts,
cameraPermissionAlert: cameraPermissions
)
var style = MBUIOptions(
showProgressBar: false,
showFaceStatusLabel: false,
showCountdownTimerLabel: false,
presentedDismissButtonEnabled: false,
textLocalizations: textLocalizations
)
self.viewContoller = MBCaptureSessionViewController(with: options, style: style)
super.init(nibName: nil, bundle: nil)
self.viewContoller.delegate = self
}
override func viewDidLoad() { }
func onSuccess(result: MobaiBiometric.MBCaptureSessionResult) { }
func onFailure(error: MobaiBiometric.MBCaptureSessionError) { }
func onPresentedDismissTapped() { }
func onStateChanged(stateEnum: MobaiBiometric.MBCaptureState) { }
}
// Implementing View
cclass ExampleViewController: MBCaptureSessionDelegate {
private let mbCaptureSessionView: MBCaptureSessionView
public init() {
var cameraPermissionAlert = CameraPermissionAlert(
title: "To continue the app need access for settings!",
message: "Go to Settings?",
settingText: "Settings",
cancelText: "Cancel"
)
var faceStatus = MBFaceStatusTexts(
faceTooFarAway: "Face too far away",
faceTooFarUp: "Face too far up",
faceTooFarDown: "Face too far down",
faceTooFarLeft: "Face too far left",
faceTooFarRight: "Face too far right",
faceTooClose: "Face too close",
faceNotFound: "Face not found",
tooManyFaces: "Too many faces",
validFace: "Valid face"
)
var options = MBCaptureSessionOptions(
autoCaptureEnabled: true,
numberOfFramesBeforeCapture: 0,
numberOfFrameToCollect: 3,
frameInterval: 10,
faceQualityEnabled: false,
isDebugging: false,
timeBeforeAutomaticCapture: 1,
cameraPosition: .front,
presentedDismissButtonEnabled: false,
targetResolutionPad: .hd1280x720,
previewScaleType: .fit,
cameraPermissionAlert: cameraPermissionAlert,
faceStatusTexts: faceStatus,
showCountdownTimerLabel: false,
showProgressBar: false,
showFaceStatusLabel: false,
countdownLabelText: "Hold Still",
payloadOptimization: false
)
self.mbCaptureSessionView = MBCaptureSessionView(options: options)
}
func onInitializing() { }
func onCaptureStarted() { }
func onCaptureFinished(result: MBCaptureSessionResult) { }
func onValidating(_ faceStatus: DetectedFaceStatus) { }
func onCountDown(time: Int) { }
func onCaptureProgress(captureProgressCounter: Float) { }
func onFailure(error: MBCaptureSessionError) { }
}
// Implementing View Controller
class ExampleViewController: UIViewController, MBCaptureSessionVCDelegate {
var viewContoller: MBCaptureSessionViewController
public var onEditTappedCallBack: (() -> ())?
public var onCompleteCallBack: ((MBCaptureSessionResult, _ captureProcessTime: Double?) -> ())?
init() {
var cameraPermissionAlert = CameraPermissionAlert(
title: "To continue the app need access for settings!",
message: "Go to Settings?",
settingText: "Settings",
cancelText: "Cancel"
)
var faceStatus = MBFaceStatusTexts(
faceTooFarAway: "Face too far away",
faceTooFarUp: "Face too far up",
faceTooFarDown: "Face too far down",
faceTooFarLeft: "Face too far left",
faceTooFarRight: "Face too far right",
faceTooClose: "Face too close",
faceNotFound: "Face not found",
tooManyFaces: "Too many faces",
validFace: "Valid face"
)
var options = MBCaptureSessionOptions(
autoCaptureEnabled: true,
numberOfFramesBeforeCapture: 0,
numberOfFrameToCollect: 3,
frameInterval: 10,
faceQualityEnabled: false,
isDebugging: false,
timeBeforeAutomaticCapture: 1,
cameraPosition: .front,
presentedDismissButtonEnabled: false,
targetResolutionPad: .hd1280x720,
previewScaleType: .fit,
cameraPermissionAlert: cameraPermissionAlert,
faceStatusTexts: faceStatus,
showCountdownTimerLabel: false,
showProgressBar: false,
showFaceStatusLabel: false,
countdownLabelText: "Hold Still",
payloadOptimization: false
)
self.viewContoller = MBCaptureSessionViewController(options: options)
super.init(nibName: nil, bundle: nil)
self.viewContoller.delegate = self
}
override func viewDidLoad() { }
func onSuccess(result: MBCaptureSessionResult) { }
func onFailure(error: MBCaptureSessionError) { }
func onPresentedDismissTapped() { }
}