# Kiosk mode features

# Kiosk mode features

Kiosk mode is used for building iPad apps where an iPad is embedded into an Aila frame and positioned in a landscape orientation.

## Initialize IncdOnboarding SDK

Add the following line of code to your `AppDelegate` class:
```
IncdOnboardingManager.shared.initIncdOnboarding(url: url, apiKey: apiKey)
```

`url` and `apiKey` will be provided to you by Incode.
If you're running the app on a simulator, please set the `testMode` parameter to true.

## Kiosk 1:N Face Login - Identify a user

1:N Face login is suitable if you would like to identify a user by doing a face scan. 
This will do a face match comparison across your entire user database and check if the face corresponds to any of the approved users.

To execute 1:N Face Login call `startFaceLogin` method:

```
IncdOnboardingManager.shared.startKioskLogin() { selfieScanResult, firstName in
          guard let loginResult = selfieScanResult.faceLoginResult else {
            // Some error occured
            print(selfieScanResult.error)
            return
          }
          
          if loginResult.success == true {
            // Face auth successful
            let customerUUID = loginResult.customerUUID
            let token = loginResult.token
            let interviewId = loginResult.interviewId
          } else {
            if selfieScanResult.spoofAttempt == true {
              // Liveness failed
            } else {
              // User's face not found
            }
          }
        }
```

### Face Login result

Face Login result will have `SelfieScanResult` and `firstName` if there is a name associated to this user, otherwise `firstName` will be `nil`.

The resulting `SelfieScanResult` object will have:
* `faceLoginResult` - `FaceLoginResult` object that contains:
  * `success` - True if face login was successful, false otherwise.
  * `customerUUID` - Customer UUID of the matched user, nil otherwise.
  * `token` - Customer token of the matched user, nil otherwise.
  * `interviewId` - Session interviewId from which the user got approved.
  * `interviewToken` - Session interviewToken which was used during user approval.
  * `transactionId` - Transaction ID of the face login attempt.
* `spoofAttempt` - Specifies if it was a spoof attempt or not
* `image` - Selfie image taken during Selfie scan step
* `error` - `SelfieScanError` that describes the error that happened during face login

## Kiosk flow - Create an account for unrecognized users

Kiosk flow will first try to recognize a user by performing a selfie scan, and in case a user is recognized the flow will end and `onKioskFlowCompleted` method of the delegate will be called.

If a user isn't recognized, a new onboarding session is created and the user will be asked to scan their ID, after which a face math comparions will be performed between the front photo ID and Selfie. Afterwards, user approval will be performed and the result will be returned as `KioskFlowResult` via `onKioskFlowCompleted`delegate method.

```
IncdOnboardingManager.shared.startKioskFlow(delegate: self)
```

As the user is going through the steps, these methods of the delegate will be called:

```
  /**
   Called when user dismisses flow.
   */
  func userCancelledSession()

  /**
   Called when selfie scan is completed
   */
  func onSelfieScanCompleted(_ result: SelfieScanResult?)

  /**
   Called when Kiosk flow is completed
   */
  func onKioskFlowCompleted(_ result: KioskFlowResult)

  /**
   Called when ID front scan is completed
   */
  func onIdFrontCompleted(success: Bool)

  /**
   Called when ID back scan is completed
   */
  func onIdBackCompleted(success: Bool)

  /**
   Called when ID is processed
   */
  func onIdProcessed(success: Bool, ocrData: OmniGetOCRDataResponse?)

  /**
   Called when face match is performed
   */
  func onFaceMatchCompleted(success: Bool)

  /**
   Called when some error occured during Kiosk flow
   See IncdFlowError documentation for specific error descriptions
   */
  func onKioskError(_ error: IncdFlowError)
}
```

### Kiosk flow result

The resulting `KioskFlowResult` object will have:
  * `success` - True if flow was successful, false otherwise.
  * `customerUUID` -  ID of the user. Will be available only if the flow is completed successfully, nil otherwise.
  * `token` - Access token. WIll be available only if the flow is completed successfully, nil otherwise.
  * `name` - Name of the user. Will be available only if the flow is completed successfully, nil otherwise.
  * `existingUser` - Boolean indicator if the user was already in the database, or new user was created.
