# NFC Scan - Integration & Usage Guide

## Prerequisites

- IncdOnboarding variant including "-nfc", eg. version "5.33.0-s-nfc".

## Integration

- Turn on Near Field Communication Tag Reading under the Capabilities tab for the project’s target. This step:
  - Adds the NFC tag-reading feature to the App ID.
  - Adds the Near Field Communication Tag Reader Session Formats Entitlement to the entitlements file.
- Add the `NFCReaderUsageDescription` key as a string item to the `Info.plist` file. For the value, enter a string that describes the reason the app needs access to the device’s NFC reader. If the app attempts to read a tag without providing this key and string, the app will crash.

- Add interface for interacting with an _ISO 7816_ tag to App's `Info.plist`:

```undefined
  <key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
    <array>
      <string>A0000002471001</string>
      <string>A0000002472001</string>
      <string>00000000000000</string>
    </array>
  ```

- If integrating through Cocoapods then no further actions are required.
- If manually integrating: Add `OpenSSL.xcframework` to your project (should be Embedded & signed). In build settings for key `LD_RUNPATH_SEARCH_PATHS` add path `@executable_path/Frameworks`.

## Usage

To add NFC Scan module to the flow, simply:

1. Add it to a `IncdOnboardingFlowConfiguration`:

```undefined
   flowConfig.addNfcScan(showNFCSymbolConfirmationScreen: true/false, processNFCData: true/false)
   ```

2. Add callback to your `IncdOnboardingDelegate`:

```undefined
   func onNFCScanCompleted(_ result: NFCScanResult) {
       // process result
   }
   ```

##### Parameters for `addNfcScan()`:
- `showNFCSymbolConfirmationScreen`: Show Is NFC Available screen. Default is `true`.
- `showInitialDataConfirmationScreen`: Show edit OCR screen at beginning of module. Default is `true`.
- `processNFCData`: A Boolean value that indicates whether to proces NFC data on backend or not. Default is `true`.

##### Returning result of the module is a 'NFCScanResult' struct which contains:
- `facePhoto`: A face photo extracted from NFC chip.
- `dg1`: DG1 data extracted from NFC chip.
- `error`: An NFC Scan error. `nil` means there were no errors.

##### Possible values for `NFCScanError`:
- `error(_ error: IncdError)`: The associated value contains the specific `IncdError` case.
- `notAvailable`: NFC scan is not available.
- `userDocumentHasNoChip`: User selected **NO** for NFC chip availability.
- `noScanAttemptsRemaining`: User has used all NFC scan attempts without success.
