Implementation¶
Import¶
import IDLiveDocCaptureIAD
Instantiate¶
Instantiate and configure the capture module
Instantiate an IDCameraController. It will communicate with your code by using IDCameraControllerDelegate protocol. Set your class as delegate.
Configure it's behavior as necessary.
// instantiate the camera controller
let vc = IDCameraController.instantiate(delegate: self)
Present the view controller¶
Present
Present the view controller.
self.show(vc, sender: nil)
It will ask the user for photo permission if needed, but you might want to check that in advance before presenting it.
import AVFoundation
//get the status of an app’s authorization to capture media.
let status = IDCameraController.authorizationStatus
//TODO: handle status
//or request with completion
IDCameraController.requestAccess { isGranted in
}
User will take a photo, either manually or automatically using document detection logic. When it happens, delegate method cameraController(_, didCaptureImage:) will be called.
Receive the photo¶
Receive the photo
Receive the photo from the delegate method parameter. Alternatively, if you wish to use IAD, use createIADBundle() method to create the IAD bundle. This binary bundle will contain all necessary information for sending to server, including the photo.
func cameraController(_ controller: IDCameraControllerBase, didCaptureImage image: IDImage) {
//Stop the video camera capture session
controller.controller.stopRunning()
do {
let bundle = try controller.createIADBundle()
//TODO: send bundle to server
} catch {
//TODO: handle error
print(error)
}
// ...
// Dismiss IDCameraController
controller.dismiss(animated: true)
}
If delegate method cameraController(_, didEncounterError error:) is called, dismiss the camera controller and handle the error in your app.
func cameraController(_ controller: IDCameraControllerBase, didEncounterError error: IDCameraController.Error) {
print("camera error: \(error), dismissing")
controller.dismiss(animated: true)
}