> For the complete documentation index, see [llms.txt](https://docs.sentiance.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sentiance.com/getting-started/sdk-integration/3.-sdk-initialization/ios.md).

# iOS

Initialization allows the SDK to perform detections in the background. You must always initialize the SDK before interacting with it. Only a limited set of SDK methods are safe to invoke on an uninitialized SDK.

### Steps

{% stepper %}
{% step %}

### Create an AppDelegate Class

Initialization must be done in the <mark style="color:$success;">**`application:didFinishLaunchingWithOptions:`**</mark> method of your <mark style="color:$success;">**`AppDelegate`**</mark> class. If you don't already have a custom AppDelegate set up, first create a new class that extends <mark style="color:$success;">**`UIApplicationDelegate`**</mark>.

<details>

<summary>UIKit app</summary>

```swift
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        true
    }
}
```

</details>

<details>

<summary>SwiftUI app</summary>

{% code fullWidth="false" %}

```swift
class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {        
        return true
    }
}

struct MyApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        ..
    }
}
```

{% endcode %}

</details>
{% endstep %}

{% step %}

### Initialize the SDK

In the <mark style="color:$success;">**`application:didFinishLaunchingWithOptions:`**</mark> method of your <mark style="color:$success;">**`AppDelegate`**</mark> class, call <mark style="color:$success;">**`initializeAsync()`**</mark>.

{% hint style="danger" %}
You must call **`initializeAsync()`**  on the main thread, directly from within **`application:didFinishLaunchingWithOptions:`**. Do not postpone the call or move it to a background thread, otherwise SDK detections will become unreliable.

To minimize the impact of initializing the SDK on your app's startup duration, we have designed **`initializeAsync()`** to be very light and fast.

For more information about this requirement, see [this page](/sdk/appendix/user-deletion.md).
{% endhint %}

```swift
import SENTSDK

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        let options = SENTOptions(for: .appLaunch)
        Sentiance.shared.initializeAsync(options: options, launchOptions: launchOptions) { result, error in
            if let result {
                NSLog("Initialization succeeded")
            }
            else if let error {
                NSLog("Initialization failed with reason \(error.failureReason)")
            }
        }
        
        return true
    }
}
```

{% endstep %}

{% step %}

### Next: User Creation

After having successfully initialized the Sentiance SDK, you must now create a user. To do so, follow the instructions on [this page](/getting-started/sdk-integration/4.-user-creation.md).
{% endstep %}
{% endstepper %}
