# iOS

Use Kvalifika SDK to easily integrate into your Android app. Before integrating Kvalifika, it is recommended to follow the steps described in [Integration Guide](https://kvalifika.gitbook.io/kvalifika-1/integration/integration-guide) and [Initial Setup](https://kvalifika.gitbook.io/kvalifika-1/integration/initial-setup).

{% hint style="warning" %}
Naming of the properties and functions might be slightly modified depending on the version.
{% endhint %}

## Installation

Add the following to the project's main `Podfile` file:

```swift
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Kvalifika/kvalifika-cocoapods-specs.git'
source 'https://github.com/Kvalifika/zoom-cocoapods-specs.git'

platform :ios, '11.0'

# Your Target
target 'kvalifika-swift-sample' do
  use_frameworks!

  pod 'Kvalifika'
end
```

If you want to update pod run in terminal:

`pod update Kvalifika`

## Initialize the SDK

import Kvalifika

After that, you need to initialize SDK with **your `appId`**.

{% hint style="info" %}
**`appId`** is Application ID, generated from Admin Panel. See [Initial Setup](https://kvalifika.gitbook.io/kvalifika-1/integration/initial-setup#retrieve-application-ids) for details.
{% endhint %}

```swift
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        // Initialize SDK and provide names of images
        KvalifikaSDK.initialize(
            AppID: "YOUR APP ID",
            Locale:  KvalifikaSDKLocale.GE.rawValue,
            Logo: "AppLogo",
            DocumentIcon: "DocLogo",
            CancelIcon: "cancel",
            ActiveFlashIcon: "",
            InactiveFlashIcon: "",
            onInitialize: onInitialize,
            onStart: onStart,
            onFinish: onFinish,
            onError: onError
        )
    }

    func onInitialize() {
        // Start session right after initialization
        let _ = KvalifikaSDK.startSession(onViewController: self)
    }

    func onStart(sessionId: String) {
        print("onStart")
    }

    func onFinish(sessionId: String) {
        print("onFinish")
    }

    func onError(error: KvalifikaSDKError) {
        print(error)
    }
}
```

## App Permissions

Please add the following permissions to your app's `Info.plist`, so that the Kvalifika iOS SDK can access a user's camera to run a verification. You can do this in the property list view or by code. Right-click on *Info.plist* and select Open As -> Source Code. Add the lines below somewhere inside the file  `<dict> </dict>`

```markup
<!-- permission strings to be include in info.plist -->
<key>NSCameraUsageDescription</key>
<string>Please give us access to your camera, to complete the verification.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Please give us access to your photo library to verify you.</string>
```

## Start Verification

&#x20;Call `Kvalifika.startSession()` on button click event

```swift
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        // Initialize SDK
        KvalifikaSDK.initialize(
            AppID: "YOUR APP ID",
            Locale:  KvalifikaSDKLocale.GE.rawValue,
            Logo: "AppLogo",
            DocumentIcon: "DocLogo",
            CancelIcon: "cancel",
            ActiveFlashIcon: "",
            InactiveFlashIcon: "",
            onInitialize: onInitialize,
            onStart: onStart,
            onFinish: onFinish,
            onError: onError
        )
    }

    func onInitialize() {
        print("onInitialize")
    }

    func onStart(sessionId: String) {
        print("onStart")
    }

    func onFinish(sessionId: String) {
        print("onFinish")
    }

    func onError(error: KvalifikaSDKError) {
        print(error)
    }

    @IBAction func onStart(_ sender: Any) {
        let _ = KvalifikaSDK.startSession(onViewController: self)
    }
}
```

## Handling Verifications

It's useful to know that whether a user has completed the verification flow or canceled it. For this, you can implement the callback methods.

## Callback Methods

| Method       | Description                                                                                        |
| ------------ | -------------------------------------------------------------------------------------------------- |
| onInitialize | This callback method is triggered when SDK is initialized.                                         |
| onStart      | This callback method is triggered when the user starts verification.                               |
| onFinish     | This callback method is triggered when the user completes verification. Get session data here.     |
| onError      | This callback method is triggered on error  (see [Error Codes](#error-codes) for more information) |

```swift
    func onInitialize() {
        print("onInitialize")
        // Start session right after initialization
        let _ = KvalifikaSDK.startSession(onViewController: self)
    }

    func onStart(sessionId: String) {
        print("onStart")
    }

    func onFinish(sessionId: String) {
        // Fetch session data here from your server
        print("onFinish")
    }

    func onError(error: KvalifikaSDKError) {
        print(error)
    }
```

## Error Codes

| Error Code                       | Description                                                                              |
| -------------------------------- | ---------------------------------------------------------------------------------------- |
| INVALID\_APP\_ID                 | Kvalifika App Id is incorrect                                                            |
| USER\_CANCELLED                  | User canceled before completing verification.                                            |
| TIMEOUT                          | Canceled due to inactivity.                                                              |
| SESSION\_UNSUCCESSFUL            | The Session was not performed successfully                                               |
| ID\_UNSUCCESSFUL                 | The ID Scan was not performed successfully and identity document data was not generated. |
| CAMERA\_PERMISSION\_DENIED       | Camera is required but access is prevented by user settings.                             |
| LANDSCAPE\_MODE\_NOT\_ALLOWED    | Verification was canceled because the device is in landscape mode.                       |
| REVERSE\_PORTRAIT\_NOT\_ALLOWED  | Verification was canceled because the device is in reverse portrait mode.                |
| FACE\_IMAGES\_UPLOAD\_FAILED     | Could not upload face images. Internal request failed.                                   |
| DOCUMENT\_IMAGES\_UPLOAD\_FAILED | Could not upload ID card or passport images. Internal request failed.                    |
| NO\_MORE\_ATTEMPTS               | User has reached maximum limit of attempts                                               |
| UNKNOWN\_INTERNAL\_ERROR         | Session failed because of an unhandled internal error.                                   |

## UI Customizations

### Appearance

It is possible to customize the logo and icons and provide resource names.

```swift
KvalifikaSDK.initialize(
    Logo: "AppLogo",
    DocumentIcon: "DocLogo",
    CancelIcon: "cancel",
    ActiveFlashIcon: "",
    InactiveFlashIcon: "",
)
```

### Language

It is possible to set locale when initializing SDK. Supported locales are:

| Code | Language |
| ---- | -------- |
| EN   | English  |
| GE   | Georgian |
| RU   | Russian  |
| SP   | Spanish  |

```swift
sdk = KvalifikaSDK.initialize(
    Locale: KvalifikaSDKLocale.EN.rawValue
)
```

## Development Mode

Without specifying mode SDK uses <https://api.kvalifika.com>

With development mode ON SDK uses <https://apistaging.kvalifika.com>

```swift
KvalifikaSDK.initialize(
   AppID: "YOUR APP ID"
   Development: true
)
```
