ID Capture
You can access the ID Capture module from the sharedInstance
property as shown below.
Before using this module please make sure you've initialized the SDK correctly.
let amaniIDCapture = Amani.sharedInstance.IdCapture()
Setting the type
Since we support many ID cards and passports you need to set the type before setting the actual type of the ID or passport with setType
method. This type is supplied by Amani.
amaniIDCapture.setType("XXX_ID_0")
XXX_ID_0
is the example. You have to specify the type that provided by Amani.
If you don't specify the type, SDK will throw an exception.
Configuration Settings
The setIdHologramDetection(enabled: true)
function enables or disables the detection of holograms during the ID capture process. When hologram detection is enabled, the system will actively analyze the document for holograms, improving the accuracy of detection in cases where holographic elements are present. This feature is particularly useful for documents with security features that may otherwise affect the capture process. If disabled, the capture process will proceed without checking for holograms, allowing for faster processing but with less accuracy for documents containing holograms. It should be called just before the Amani.sharedInstance().IDCapture..start(...) function.
amaniIDCapture.setIdHologramDetection(enabled: true)
The setVideoRecording(enabled: true)
function enables or disables the video recording feature during the ID capture process. When video recording is enabled, the system will continuously record the capture session, which can be useful for auditing or additional analysis. If disabled, the capture will proceed without recording, allowing for a streamlined process without the overhead of video storage.
amaniIDCapture.setVideoRecording(enabled: true)
The setManualCropTimeout()
sets the manual capture button of the IDCapture
fragment for the situations where AutoCapture can fail.
When the manual crop button is enabled, user will have a chance to capture
the document manually for unexpected situations. It must be called just before the Amani.sharedInstance().IDCapture..start(...) function.
If you did not called this method. It will use the default value as 30
seconds.
amaniIDCapture.setManualCropTimeout(Timeout: 30)
Starting the document
ID Card's has 2 sides, so we have to tell the start
method to capture which side of the ID we're taking by setting the stepId
parameter.
Callback on the start
method will return UIImage
so you can preview before upload.
The method itself will return an instance of UIView
. You should add this as a subview to your
view controller.
// stepId is the document page count. This value is calculated as n-1
// for example 2 sided ID Card has stepId 0 for front and 1 for back.
self.idCaptureView = amaniIDCapture.start(stepId: 0) {[weak self] idImage in
// idImage is UIImage that you can use to preview
// TODO: Show a preview screen or directly start the back side
// After the callback ends don't forget to remove the idCaptureView from your controller
DispatchQueue.main.async {
self.idCaptureView.removeFromSuperview()
}
}
Scanning the NFC
If you want to capture the NFC data can be found inside the ID as a part of the ID document
you can use the startNFC
method before uploading the document.
Starting the NFC Capture
There are two ways to capture the NFC Data as a part of the ID.
Capturing the NFC data after ensuring both sides are captured and before the upload.
When you used MRZ model, you need to set NVI Data according to MRZInfoDelegate.
var nviData:NviModel? {
didSet{
Task { @MainActor in
if let nviData = nviData {
let scannfc = await amaniScanNFC.startNFC(nvi: nviData)
}
}
}
}
amani.IdCapture().getMrz { [weak self] mrzDocumentId in
self?.mrzDocumentId = mrzDocumentId
}
MRZInfoDelegate will be changed according to API version. If you're using API .v2 getMrz request has an id, it's showing as mrzDocumentId and you need to cross check what delegates returns to you as documentId.
extension ViewController:mrzInfoDelegate{
func mrzInfo(_ mrz: AmaniSDK.MrzModel?, documentId: String?) {
guard let mrz = mrz else {return}
switch apiVersion {
case .v1:
let nviData = NviModel(mrzModel: mrz)
self.nviData = nviData
case .v2:
if documentId == mrzDocumentId {
let nviData = NviModel(mrzModel: mrz)
self.nviData = nviData
}
default:
break
}
}
}
Starting the NFC Capture with NVI data
NviModel
contains some information about the ID that we need to read the NFC data.
let nviData = NviModel(
documentNo: "Documnet number on id",
dateOfBirth: "YYMMDD",
dateOfExpire: "YYMMDD"
)
do{
try await amaniIDCapture.startNFC(nviData: nviData)
} catch (let error ) {
print(error)
}
Upload the document
After all sides are captured, you can upload the captured document by using the upload
method on the IdCapture
module.
The first parameter on the callback states if the upload has completed successfuly.
Final validation response will be delivered from AmaniDelegate.onStepModel
delegate method.
idCaptureModule.upload(location: nil) {[weak self] uploadSuccess in
if (uploadSuccess != nil) {
// uploadSuccess is a boolean variable
// Upload successfuly completed
// TODO: handle the upload state
}
}