iOS AutoCapture¶
Overview¶
BiometridStandardAutoCapture provides automatic document capture and camera functionality for iOS. It supports two capture modes: document capture (using CoreML for detection) and face comparison (using CoreML for face detection). The module can operate in auto-capture mode with ML-powered detection or as a simple manual camera.
Prerequisites¶
- BiometridStandardCore must be initialized first
- iOS 13.0 or higher
- Camera permission granted (add
NSCameraUsageDescriptionto Info.plist)
Initialization¶
BiometridStandardAutoCapture is accessed through a singleton object. On iOS, no explicit initialization call is needed -- just set the callback and start using the module.
import BiometridStandard
Available Methods¶
set¶
func set(callback: BiometridStandardAutoCaptureCallback)
Sets the callback to receive capture results.
| Parameter | Type | Description |
|---|---|---|
callback |
BiometridStandardAutoCaptureCallback |
Callback to receive capture results |
configure¶
func configure(modelType: AutoCaptureModelType)
Configures the ML model type used for auto-capture detection.
| Parameter | Type | Description |
|---|---|---|
modelType |
AutoCaptureModelType |
The detection model to use |
startCapture¶
func startCapture(side: DocumentSide, orientation: CaptureOrientation)
Starts the auto-capture camera with ML-powered document detection. The camera will automatically capture when a valid document is detected.
| Parameter | Type | Default | Description |
|---|---|---|---|
side |
DocumentSide |
- | Which side of the document to capture (front or back) |
orientation |
CaptureOrientation |
landscape |
Camera orientation (portrait or landscape) |
startCamera¶
func startCamera(orientation: CaptureOrientation)
Starts a simple manual camera without auto-capture detection. The user manually triggers the capture.
| Parameter | Type | Default | Description |
|---|---|---|---|
orientation |
CaptureOrientation |
landscape |
Camera orientation (portrait or landscape) |
stopCapture¶
func stopCapture()
Stops the current capture session and releases camera resources.
setStrings¶
func setStrings(strings: AutoCaptureStrings)
Sets custom localized strings for the capture UI.
| Parameter | Type | Description |
|---|---|---|
strings |
AutoCaptureStrings |
Custom strings for the capture screens |
Callback Interface¶
BiometridStandardAutoCaptureCallback¶
protocol BiometridStandardAutoCaptureCallback {
func capturedWithSuccess(result: UIImage?)
func capturedWithError(error: BiometridErrorInfo?)
func captureCancelled()
}
On iOS, PlatformImage is a type alias for UIImage.
| Method | Description |
|---|---|
capturedWithSuccess(result:) |
Called when a document is successfully captured. Returns a UIImage of the captured image. |
capturedWithError(error:) |
Called when capture fails. |
captureCancelled() |
Called when the user cancels the capture. |
Enums¶
AutoCaptureModelType¶
| Case | Description |
|---|---|
documentCapture |
CoreML model for document detection |
faceCompare |
CoreML model for face comparison/detection |
DocumentSide¶
| Case | Description |
|---|---|
front |
Front side of document |
back |
Back side of document |
CaptureOrientation¶
| Case | Description |
|---|---|
portrait |
Portrait camera orientation |
landscape |
Landscape camera orientation |
Data Models¶
BiometridErrorInfo¶
class BiometridErrorInfo {
var code: String?
var message: String?
var data: Any?
}
AutoCaptureStrings¶
class AutoCaptureStrings {
var camera: CameraStrings
var simpleCamera: SimpleCameraStrings
var permissions: ACPermissionsStrings
}
class CameraStrings {
var centerCard: String // Default: "Please center your card within the frame"
var verifying: String // Default: "We are verifying...."
var taskValidated: String // Default: "Card successfully scanned, thank you!"
}
class SimpleCameraStrings {
var centerCard: String // Default: "Please center your card within the frame"
var validateOrRetry: String // Default: "Please validate the picture or try again"
}
class ACPermissionsStrings {
var cameraRequired: String // Default: "Camera Permission Required"
var cameraNeeded: String // Default: "Camera permission is needed to capture photos..."
var grantPermission: String // Default: "Grant Permission"
var cancel: String // Default: "Cancel"
var permissionDenied: String // Default: "Permission Denied"
var permanentlyDenied: String // Default: "Camera permission was permanently denied..."
var openSettings: String // Default: "Open Settings"
}
Error Codes¶
AutoCapture errors use the prefix MSA. Common error codes:
| Code | Description |
|---|---|
MSABSSC001 |
SDK not initialized (startCapture called before initialize) |
MSABSCA001 |
Inference error during ML detection |
MSABSCA002 |
Camera cancelled by user |
MSABSCA003 |
Camera permission denied |
Error Handling¶
Errors are returned as BiometridErrorInfo objects through the capturedWithError callback. All error codes are prefixed with MSA (AutoCapture module).
Usage Example¶
import BiometridStandard
class DocumentCaptureViewController: UIViewController, BiometridStandardAutoCaptureCallback {
override func viewDidLoad() {
super.viewDidLoad()
// Step 1: Set the callback
BiometridStandardAutoCapture.shared.set(callback: self)
// Step 2: Configure the model type
BiometridStandardAutoCapture.shared.configure(modelType: .documentCapture)
// Step 3: Start auto-capture for front of document
BiometridStandardAutoCapture.shared.startCapture(side: .front, orientation: .landscape)
}
// MARK: - Callback Methods
func capturedWithSuccess(result: UIImage?) {
guard let image = result else { return }
// Process the captured document image
// Convert to base64 or upload to server
}
func capturedWithError(error: BiometridErrorInfo?) {
print("Capture failed: \(error?.message ?? "")")
}
func captureCancelled() {
print("Capture cancelled by user")
}
// Capture back side
func captureBackSide() {
BiometridStandardAutoCapture.shared.startCapture(side: .back, orientation: .landscape)
}
// Use simple manual camera in portrait
func useManualCamera() {
BiometridStandardAutoCapture.shared.startCamera(orientation: .portrait)
}
// Customize UI strings
func customizeStrings() {
let strings = AutoCaptureStrings(
camera: CameraStrings(
centerCard: "Centre o seu cartão na moldura",
verifying: "A verificar...",
taskValidated: "Cartão digitalizado com sucesso!"
),
simpleCamera: SimpleCameraStrings(),
permissions: ACPermissionsStrings()
)
BiometridStandardAutoCapture.shared.setStrings(strings: strings)
}
deinit {
BiometridStandardAutoCapture.shared.stopCapture()
}
}