NFC
You can access the ScanNFC
module from the base Amani
class as shown below.
let amaniScanNFC = Amani.sharedInstance.scanNfc()
let amani = Amani.sharedInstance
There are tree ways to start the NFC capture process.
Starting the NFC Capture with NVI Data
In this scenario, you need to gather some information that can be found on ID from the user.
In order to capture NFC without capturing the ID first, and upload the data as a
separate document you need to call setType as documentTypes.NFCDocument.rawValue
If you have an another type supplied from us please use it.
amaniScanNFC.setType(type: documentTypes.NFCDocument.rawValue)
let nviData = NviModel(documentNo: "DOCUMENT NO IN ALL CAPS", dateOfBirth: "YYMMDD", dateOfExpire: "YYMMDD")
do{
let scannfc = try await amaniScanNFC.startNFC(nvi: nviData)
} catch (let error ) {
print(error)
}
Starting the NFC capture with image of the MRZ sided ID
If you cache the back side of the ID, or the image of the passport itself, you can call the function below to start the nfc capture process.
idCardType
parameter is the type that you've used while capturing the image.
Starting the NFC capture with ID Capture
You can also capture the MRZ side yourself with this function. It'll return an instance of UIView
, so you'll need to capture the correct side of the ID.
If you want the NFC capture with process of ID Capture, please check out scanning the nfc section on ID Capture Page.
Please don't forget the change the XXX_ID_0
to a type given by Amani.
self.captureView = amaniScanNFC.start(idCardType: "XXX_ID_0") {(data, error) in
//data in NFCRequest type and it contains nfc information, if there is an error this value can be null
//error in AmaniError type and if there is no error it can be null
guard let data:NFCRequest = data else {
return
}
DispatchQueue.main.async {
self.captureView.removeFromSuperview()
}
}
DispatchQueue.main.async {
self.view.addSubView(self.captureView)
}
var nviData:NviModel? {
didSet{
Task { @MainActor in
if let nviData = nviData {
let scannfc = await amaniScanNFC.startNFC(nvi: nviData)
}
}
}
}
var stepId = steps.front.rawValue //For ID's which has MRZ Field at the front side (like passport)
let type = "XXX_ID_0"
if((type.contains("ID"))){
stepId = steps.back.rawValue ////For ID's which has MRZ Field at the back side (like ID Cards)
}
guard let idcaptureVC:UIView = try idcapture.start(stepId: stepId, completion: { [weak self] (previewImage) in
amani.IdCapture().getMrz { [weak self] mrzDocumentId in
self?.mrzDocumentId = mrzDocumentId
}
}
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
}
}
}
Upload
After completing the capture process you can call the upload as shown below.
amaniScanNFC.upload(location: nil) {[weak self] uploadSuccess in
if (uploadSuccess != nil) {
// uploadSuccess is a boolean variable
// TODO: handle the upload state
}
}