Skip to main content

NFC

The NFC module reads the chip of an ID card or passport with its MRZ data, either from a captured ID or from values you already know.

Flow overviewFlowchart of this module's usage within the SDK flow. Expand to view it, click the chart to enlarge.

NFC scan with known MRZ data (no ID photo)

NFC-only flow

  • C1, C2: set AmaniDelegate, then start the session.
  • C3: build NviModel(documentNo:dateOfBirth:dateOfExpire:) from the values you already know (dates YYMMDD, document number in capitals).
  • C4: scanNFC().setType(...), then startNFC(nvi:); if the chip is not read, scan again and check the values with the user.
  • C5: upload the chip. If the upload fails or the step is REJECTED, do not call upload() again: the data is cleared after it. Open the chip scan again (call start() and add the new view, or show your kept view again), capture, then upload, up to your own max attempt.

ID capture with NFC

ID capture with NFC flow

  • N1: set AmaniDelegate, start the session, and set the MRZ delegate with setMRZDelegate(delegate:).
  • N2: capture the ID side with the MRZ (stepId: 1 for ID cards, 0 for passports), with setManualCropTimeout set before start().
  • N3: getMrz { mrzDocumentId in }; the MRZ arrives in mrzInfo(_:documentId:), build NviModel(mrzModel:) from it. If it cannot be read, let the user type the values or capture again.
  • N4: startNFC(nviData:): iOS shows its NFC sheet (iOS 13+, NFC capability and Info.plist keys needed); retry if the chip is not read.
  • N5: upload the ID; the chip data goes with it. If the upload fails or the step is REJECTED, do not call upload() again: the data is cleared after it. Open the ID capture and the chip scan again (call start() and add the new view, or show your kept view again), capture, then upload, up to your own max attempt.

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​

↑ Flow steps C3 C4

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

note

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​

↑ Flow steps N2 N3 N4

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.

note

If you want the NFC capture with process of ID Capture, please check out scanning the nfc section on ID Capture Page.

caution

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​

↑ Flow steps N5 · C5

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
}
}

Getting the documentId after the upload​

Starting with AmaniSDK 3.7.6, upload also accepts a closure with two parameters. The second parameter is the documentId of the document that the upload created.

amaniScanNFC.upload(location: nil) { isSuccess, documentId in
if isSuccess == true, let documentId {
// Upload succeeded, store the documentId
print("Upload completed, documentId: \(documentId)")
} else {
// Upload failed, documentId is nil
}
}
note

The closure with only isSuccess still works. You don't need to change your existing integration.