Scanning documents with NFC
Overview
Since iOS 13, NFC reading feature is avaliable in iPhone, and so it's on MobbScan SDK. 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
This feature is only available from iOS 13, so if you want to use it in your application, you must set your Deployment Target to iOS 13 or higher.
Regarding hardware support, NFC reading is only supported on iPhone 7 and newer models. iPhone 6 has some NFC features, but they are restricted to Apple Pay and some Apple applications. This makes it impossible for MobbScan to use the NFC chip in devices older than the iPhone 7.
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 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
. 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>
Warning!: The NFC feature is only avaliable for iOS 13. For devices that have an older iOS version this feature will not work. Furthermore, there are some frameworks that are only available on the iOS 13 core. In order to execute applications with this framework in devices with a lower iOS version, you must set MobbScan_NFC_Plugin framework as
optional
in the Build Phases tag:
Considerations for Objective-C: If your app is being compiled in the Objective-C platform, you'll get an error compiling in devices with a version of iOS lower than iOS 13. To solve this issue, you must set Swift Standard libraries as Always Embeded in Build Settings:
NFC scanning process
To start the NFC scanning process you should previously launch the startScan
method in order to get the scan id
. If you did not do this before, you have to call this method to get the scan id
.
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 = NfcDocumentReader.getInstance()
let extractsFace:Bool = 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 event 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 confused 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 sucess and failure results). You will receive NFC data on this block in resultData object as in every MobbScan scanning process.
Tip: You can see a clearer example in the app code provided with the SDK.