Skip to content

Integration

  • Create a new Xcode project.
  • Add required keys/values into Info.plist:

    <key>NFCReaderUsageDescription</key>
    <string>Your NFC permission message goes here</string>
    <key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
    <array>
      <string>A0000002471001</string>
      <string>00000000000000</string>
    </array>
    
  • Add a entitlements file with the following keys/values

    <key>com.apple.developer.associated-domains</key>
    <array>
      <string>applinks:dasnano.com</string>
    </array>
    <key>com.apple.developer.nfc.readersession.formats</key>
    <array>
      <string>TAG</string>
      <string>NDEF</string>
    </array>
    
  • Drag and drop VDNfcScanner.xcframework into Xcode and make sure copy is checked.
  • Add VDNfcScanner.xcframework into the targets general tab, inside Embedded Binaries and Linked Frameworks and Libraries (if they do not appear yet).
  • Import VDNfcScanner in Swift and implement VDNfcScannerControllerDelegate in the class that uses it.
  • Write down all the required delegated methods into the class that uses the framework. Call the methods of the SDK as needed.
  • Create valid Apple Identifier and Profile that supports NFC Tag Reading.

SDK update

Once a new SDK is released the following steps have to be followed to properly update the SDK.

  • Remove all updating .xcframework located in the project. Do not remove only the reference; remove the actual file if the deletion is done with the help of Xcode. Just in case, empty the bin too.
  • Compile and/or run to force errors. If no error occurs then a cached framework is in memory. Clean cache and project.
  • Add all new .xcframework and implement new interfaces if necessary.
  • Compile and run.

In case of doubt, also the following can be done.

  • Check the installed version by calling the getVersion() method.

Example of use

import UIKit
import VDNfcScanner

class ViewController: UIViewController {
    // This keys can be retrieved from server.
  let dictionaryKeys = ["DG1_OPT_DATA", "DG1_DOE", "DG1_DOC_NUMBER",
                        "DG1_NAME", "DG1_SURNAME", "DG11_PERS_NUM",
                        "DG1_NATIONALITY", "DG1_DOB", "DG1_NATIONALITY",
                        "DG11_BIRTH_PLACE", "DG1_SEX", "DG1_ADDR_LINE",
                        "DG1_ADDR_CITY", "DG1_ADDR_REGION",
                        "cut_photo"
                        ]

  @IBAction func startNfcCapture(_ sender: Any) {
    if #available(iOS 13.0, *) {
      if !NFCTagReaderSession.readingAvailable { // From CoreNFC
        // The VDNfcScanner needs iOS 13 and Nfc Tag reading support to work.
        return
      }
      // Optional but recommended step.
      if !NfcDocumentType.isValueValid(type: "ES_IDCard_2015") {
        // The document supplied is not supported by the NFC SDK.
        return
      }

      // The getNfcKeys() method should be implemented by the developer. Can be retrieved from server.
      // The getConfiguration() method should be implemented by the developer.
      let documentType = NfcDocumentType.getDocumentType(type: "ES_IDCard_2015")
      let nfcController = VDNfcScannerController(self, documentType: documentType!)
      nfcController.modalPresentationStyle = .fullScreen
      nfcController.configuration = getConfiguration()
      nfcController.keys = getNfcKeys()
      nfcController.dictionaryKeys = dictionaryKeys
      present(nfcController, animated: true, completion: nil)
    }
  }

  override func viewDidLoad() {
    super.viewDidLoad()
  }

    // This NfcKeys may be read from an image taken with our VDDocumentCapture SDK and processed in our servers.
  private func getNfcKeys() -> NfcKeys! {
    let documentNumber = DocumentNumber(value: "AAA111111")
    let birthDate = BirthDate(value: "123456")
    let expiryDate = ExpiryDate(value: "65432", checksum: nil)
    let can = CAN(value: "")

    return NfcKeys(documentNumber: documentNumber, birthDate: birthDate, expiryDate: expiryDate, can: can)
  }

  private func getConfiguration() -> NfcConfiguration {

    ////////////// Veridas' recommended configuration //////////////
    let tutorialConfiguration = NfcTutorialConfigurationBuilder(defaultLanguage: .EN)
            .setBackgroundColor(["alpha": "1", "red": "172", "green": "176", "blue": "195"])
            .setTitleTextColor(["alpha": "1.0", "red": "0", "green": "13", "blue": "68"])
            .setScanButtonTitleTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setScanButtonBackgroundColor(["alpha": "1.0", "red": "0", "green": "13", "blue": "68"])
            .setInformativeTextColor(["alpha": "1.0", "red": "0", "green": "13", "blue": "68"])
            .build()

    let keysAlertConfiguration = NfcKeysAlertConfigurationBuilder(defaultLanguage: .EN)
            .setBackgroundColor(["alpha": "1.0", "red": "0", "green": "13", "blue": "68"])
            .setTitleTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setScanButtonBackgroundColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setScanButtonTitleTextColor(["alpha": "1.0", "red": "0", "green": "13", "blue": "68"])
            .setDocumentNumberTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setDateOfBirthTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setDateOfBirthDayTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setDateOfBirthMonthTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setDateOfBirthYearTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setDateOfExpiryTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setDateOfExpiryDayTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setDateOfExpiryMonthTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .setDateOfExpiryYearTextColor(["alpha": "1.0", "red": "255", "green": "255", "blue": "255"])
            .build()

    // Here can be created custom configurations.
    return NfcConfiguration(
        tutorialConfiguration: tutorialConfiguration,
        keysAlertConfiguration: keysAlertConfiguration)
  }
}

// Called when the SDK finishes.
extension UIViewController : VDNfcScannerControllerDelegate {
  public func nfcRead(data: [String : String]?, error: Error?) {
    print("Data read: \(data?.description ?? "no data")")
    print("Error: \(error?.localizedDescription ?? "no error")")
  }
}