Installation¶
Using Zip files¶
Short integrator-oriented guide to add VeridasNfcSDK to an iOS project.
1) Download the zipped xcframework files (VeridasCommonDefinitions, VeridasCommonUtils, VeridasGenuineDS, VeridasNativeDS, VeridasNfcSDK, VeridasSDKCore), place them inside an xcframeworks/ folder in your Xcode project, add them to the target, and set each one to Embed & Sign in the target’s General settings.
The third-party code the SDK uses, including OpenSSL, is linked inside VeridasNfcSDK.xcframework with its symbols hidden, so it does not conflict with another OpenSSL version your app may include.
Enable NFC reading¶
The host app must declare the NFC capability and the related Info.plist keys. Without them, the system does not let the app open a reading session. See Specifications for details.
1) In Signing & Capabilities, add the Near Field Communication Tag Reading capability. The app entitlements must include:
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>TAG</string>
</array>
2) Add the application identifiers of the eMRTD chip to Info.plist:
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
<string>A0000002471001</string>
<string>A00000024710FF</string>
</array>
3) Add the usage description shown by the system when the reading starts to Info.plist:
<key>NFCReaderUsageDescription</key>
<string>We use NFC to read the chip of your identity document.</string>
Prepare the configuration¶
- Provide an
NfcReadConfigurationinstance (it isCodable, so you can build it in code or load it from a JSON such asnfcRead.jsoninSdkJsonConfigs/). - List in keys the data fields you want in the result. If you set none, the result carries no text field, only the photos.
- If your app already knows the document data (for example, from a previous document capture), set it as prefill to skip the form.
Minimal code usage¶
Import the SDK, create the configuration (programmatically or from JSON), and start the flow:
import UIKit
import VeridasNfcSDK
import VeridasCommonDefinitions
final class MyController: UIViewController, NfcReadDelegate, NfcReadEventsDelegate {
func startNfcRead() {
// Decode from JSON (recommended). You can also build it in code.
let config = loadConfigFromJSON("nfcRead", as: NfcReadConfiguration.self)
NfcRead.setEventsDelegate(delegate: self)
NfcRead.start(delegate: self, configuration: config)
}
// NfcReadDelegate
func onNfcReadResults(results: NfcReadResults) { print(results) }
func onNfcReadStarted() { print("SDK started") }
func onNfcReadFinished(error: NfcReadError?) { print(error as Any) }
// NfcReadEventsDelegate
func onNfcReadEvent(event: NfcReadEvent) { print(event) }
}
Optional helper to load JSON from the bundle instead of building the config inline:
private func loadConfigFromJSON<T: Decodable>(_ name: String, as type: T.Type) -> T {
guard let url = Bundle.main.url(forResource: name, withExtension: "json") else {
fatalError("Missing \(name).json in app bundle")
}
let data = try! Data(contentsOf: url)
return try! JSONDecoder().decode(T.self, from: data)
}
Example building the configuration in code:
func startNfcRead() {
let config = NfcReadConfiguration(setup: NfcSetup(language: "en",
maxRetries: 3,
keys: ["DG1_NAME", "DG1_SURNAME", "DG1_DOC_NUMBER"]))
NfcRead.setEventsDelegate(delegate: self)
NfcRead.start(delegate: self, configuration: config)
}
NfcReadDelegate covers onNfcReadResults, onNfcReadStarted, and onNfcReadFinished, while NfcReadEventsDelegate can be implemented optionally to receive tracking events through onNfcReadEvent. Details are in the API section.
Use a physical device
NFC is not available on the iOS Simulator. Use a physical iPhone to run the app that integrates the SDK.