iOS NFC
Overview
BiometridStandardNFC provides NFC document reading capabilities for iOS. It reads data from NFC-enabled identity documents (passports, national ID cards) including personal information and biometric photos. The module supports two OCR providers for MRZ (Machine Readable Zone) reading: OCR01 (Innovatrics) and OCR03 (Regula).
Prerequisites
- The Core SDK must be initialized first
- iOS 16.0 or higher
- Device must support NFC (iPhone 7 or later)
- Add NFC entitlements to your project:
- Enable "Near Field Communication Tag Reading" capability
- Add
NFCReaderUsageDescription to Info.plist
- Add
com.apple.developer.nfc.readersession.iso7816.select-identifiers to entitlements
Initialization
Create an instance of BiometridStandardNFC by providing the OCR provider and callback.
import BiometridStandard
class MyNFCCallback: BiometridStandardNFCCallback {
func readWithSuccess(result: BiometridNFCData?) {
// Handle NFC data
}
func readWithError(error: BiometridErrorInfo?) {
// Handle NFC error
}
}
let callback = MyNFCCallback()
let nfc = BiometridStandardNFC(ocrProvider: .ocr03, nfcCallback: callback)
Available Methods
Constructor
BiometridStandardNFC(ocrProvider: NfcOcrProvider, nfcCallback: BiometridStandardNFCCallback)
| Parameter |
Type |
Description |
ocrProvider |
NfcOcrProvider |
The OCR provider to use for MRZ reading |
nfcCallback |
BiometridStandardNFCCallback |
Callback to receive NFC read results |
Note: The iOS constructor does not require an Activity or Lifecycle parameter (unlike Android).
initializeReader
func initializeReader(vc: UIViewController) async -> Bool
Initializes the NFC reader and presents the NFC scanning interface. When a compatible document is detected, the module reads the chip data and delivers the result through the callback.
| Parameter |
Type |
Description |
vc |
UIViewController |
The presenting view controller for the NFC reader UI |
| Return |
Type |
Description |
| result |
Bool |
true if initialization was successful |
Callback Interface
BiometridStandardNFCCallback
protocol BiometridStandardNFCCallback {
func readWithSuccess(result: BiometridNFCData?)
func readWithError(error: BiometridErrorInfo?)
}
| Method |
Description |
readWithSuccess(result:) |
Called when NFC data is successfully read from the document |
readWithError(error:) |
Called when NFC reading fails |
Enums
NfcOcrProvider
| Case |
Description |
ocr01 |
Innovatrics OCR engine |
ocr03 |
Regula OCR engine |
Data Models
BiometridNFCData
class BiometridNFCData {
var name: String?
var surname: String?
var documentType: String?
var mrzCode: String?
var documentNumber: String?
var dateOfBirth: String?
var dateOfExpiry: String?
var gender: String?
var idNumber: String?
var nationality: String?
var photos: BiometridNFCPhotos?
}
| Property |
Type |
Description |
name |
String? |
First name(s) from the document |
surname |
String? |
Surname from the document |
documentType |
String? |
Type of document (e.g., passport, ID card) |
mrzCode |
String? |
Raw MRZ code string |
documentNumber |
String? |
Document number |
dateOfBirth |
String? |
Date of birth |
dateOfExpiry |
String? |
Document expiry date |
gender |
String? |
Gender |
idNumber |
String? |
National ID number |
nationality |
String? |
Nationality code |
photos |
BiometridNFCPhotos? |
Biometric photos from the chip |
BiometridNFCPhotos
class BiometridNFCPhotos {
var face: UIImage?
var signature: UIImage?
}
On iOS, PlatformImageType is a type alias for UIImage.
| Property |
Type |
Description |
face |
UIImage? |
Face photo from the document chip |
signature |
UIImage? |
Signature image from the document chip |
BiometridErrorInfo
class BiometridErrorInfo {
var code: String?
var message: String?
var data: Any?
}
Error Handling
Errors are returned as BiometridErrorInfo objects through the readWithError callback. Error codes are prefixed with MSN (NFC module).
Usage Example
import BiometridStandard
class NFCViewController: UIViewController, BiometridStandardNFCCallback {
private var nfc: BiometridStandardNFC?
override func viewDidLoad() {
super.viewDidLoad()
nfc = BiometridStandardNFC(ocrProvider: .ocr03, nfcCallback: self)
}
func startNFCReading() {
Task {
let success = await nfc?.initializeReader(vc: self) ?? false
if !success {
print("Failed to initialize NFC reader")
}
}
}
// MARK: - Callback Methods
func readWithSuccess(result: BiometridNFCData?) {
guard let data = result else { return }
let name = data.name
let surname = data.surname
let documentNumber = data.documentNumber
let facePhoto: UIImage? = data.photos?.face
// Process NFC data
// Submit to BiometridStandard.shared.updateStep()
}
func readWithError(error: BiometridErrorInfo?) {
print("NFC read failed: \(error?.message ?? "")")
}
}