Scanning documents with NFC
Overview
We allow you to get all the information contained on a Spanish ID card v3 or Passport by scanning a NFC chip in case of being available. NFC is a 100% reliable data source and only a few configuration steps are required to get it done.
Compatibility
An iPhone 7 or newer is required for NFC reading.
Setup configuration
Before starting the development you will need to follow these steps:
- Add
MobbScan_NFC_Plugin.xcframework
to your project:
This is a dynamic framework and must be added as an Embeded framework
You must add NFC capability ti your project. For doing this, you must go to
Signing and Capabilities
tag section, click on+Capability
and selectNear Field Communication Tag Reading
. It should look like this:Finally you have to add two keys to your
Info.plist
file. The first one isNFCReaderUsageDescription.
Under this key you must provide a description of why you are using NFC capability.The other key is
com.apple.developer.nfc.readersession.iso7816.select-identifiers
. Under this key you must provide an array of which Aplication Identifier (AID) you are using in your app. For instance, European Passports useA0000002471001
and the Spanish ID card v3 usesD4100000030001
. An example of these keys would be this:
<key>NFCReaderUsageDescription</key>
<string>NFC capability is used to read NDEF messages from id cards into the application</string>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
<string>A0000002471001</string>
<string>D4100000030001</string>
</array>
NFC scanning process
To start the NFC scanning process you should previously launch the startScan
method in order to get the scanId
.
self.mobbScanAPI.startScan(for: ._ESPIDCard, for: .SCAN_BOTH_SIDES, withResult: { result, scanId, error in
// Your block code here
})
[self.mobbscanAPI startScanForDocumentType:MobbScanDocumentType_ESPIDCard
forMode:MobbScanOperationMode_SCAN_BOTH_SIDES
withResult:^(MobbScanStartScanResult result, NSString* scanId, NSError* error) {
// Your block code here
}];
To continue, you must configure and initialize the NFC reader:
var nfcDocumentReader = NfcDocumentReader.getInstance()
let extractsFace = true
nfcDocumentReader.configureNFCExtractFace(extractsFace, scanId: "THE_SCANID_OF_THE_PROCESS", onNfcDocumentReaderFinish: { (data,error) in
// Your block code here
} ,onNfcEvent:{ (event) in
// Your block code here
})
NfcDocumentReader *nfcDocumentReader = [NfcDocumentReader getInstance];
BOOL extractsFace = YES;
[nfcDocumentReader configureNFCExtractFace:extractsFace
scanId:"THE_SCANID_OF_THE_PROCESS"
onNfcDocumentReaderFinish:^(MobbScanScanResultData *resultData, NSError *error) {
// Your block code here
} onNfcEvent:^(NFCEvent event) {
// Your block code here
}];
The method named configureService
receives four parameters:
- A flag that indicates if you want to extract the image face of the document. If you don't, the process gets faster.
- The
scanId
that identies the process. - A result block.
- An
NFCEvent
block.
The blocks ares used to notify the user of the progress of the scan process. The are described on blocks section.
After that, you have to indicate to the reader that it should start. To do this, you have to call the method readDocumentNFC
.
This method receives three parameters, the document number, the date of birth and the date of expiry. This method starts the nfc reader to read both documents, the Spanish ID card v3 and the Passport.
nfcDocumentReader.readDocumentNFC(withDocumentNumber: documentNumber, dateOfBirth: dateOfBirth, dateOfExpiry: dateOfExpiry)
[nfcDocumentReader readDocumentNFCWithDocumentNumber:documentNumber dateOfBirth:dateOfBirth dateOfExpiry:dateOfExpiry];
Blocks
Due to the scanning process could be long and confusing to the final user, the onNfcEvent
block is used to notify the developer about the state of scanning. You can receive either of this values:
typedef NS_ENUM(NSInteger, NFCEvent)
{
CONFIGURING_SERVICE = 0,
AUTHENTICATING = 1,
READING_DATA = 2 ,
READING_IMAGE = 3
};
Once we have finished to read the NFC content, we can manage the process with onNfcDocumentReaderFinish
block (both for success and failure results). You will receive NFC data on this block in a resultData
object as with every MobbScan scanning process.
Tip: You can see a clearer example in the app code provided with the SDK.