> For the complete documentation index, see [llms.txt](https://docs.movesdk.com/move-platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/api-interface/ios/intialization.md).

# Initialization

## Definition

Initialize the SDK `shared` instance and prepare the required services based on the passed [MoveConfig](/move-platform/move-sdk-1.x/sdk/models/moveconfig.md). SDK must be successfully initialized **once** before any of the SDK Services can be used. Call this API on the `shared` instance to initialize the SDK:

```swift
func initialize(auth: MoveAuth, config: MoveConfig, launchOptions: [UIApplication.LaunchOptionsKey: Any]?, completion: MoveIntializationCallback)
```

| **Parameters** |                                                                                                              |                                                                                                                                                         |
| -------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| auth           | [MoveAuth](/move-platform/move-sdk-1.x/sdk/models/moveauth.md)                                               | The user's Auth object.                                                                                                                                 |
| config         | [MoveConfig](/move-platform/move-sdk-1.x/sdk/models/moveconfig.md)                                           | The required SDK configurations.                                                                                                                        |
| launchOptions  | \[[LaunchOptionsKey ](https://developer.apple.com/documentation/uikit/uiapplication/launchoptionskey): Any]? | The launch options passed in[`willFinishLaunchWithOptions`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623032-application). |

| Callback   |                                                                                                     |                                                                                                                                                                                                       |
| ---------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| completion | [MoveIntializationCallback](/move-platform/move-sdk-1.x/sdk/models/untitled.md#initialize-listener) | Block that gets invoked on initialization completion with an optional [MoveConfigurationError](/move-platform/move-sdk-1.x/sdk/models/moveconfigurationerror.md) for potential initialization errors. |

{% hint style="warning" %}
The[`initialization`](/move-platform/move-sdk-1.x/sdk/api-interface/ios/intialization.md)API must be executed before[`willFinishLaunchingWithOptions`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623032-application)returns. We recommend calling it in [`didFinishLaunchingWithOptions`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622921-application).
{% endhint %}

## Timing

#### Why should the initialization be called before[`willFinishLaunchingWithOptions`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623032-application)returns?

Once the right permissions were granted and the MOVE SDK has been successfully initialized and started for the first time, the SDK will then set up its timers, tasks, and system triggers to be able to automatically wake up in the background and start its services, even if the app has been killed by the user.

When the app wakes up in the background because of the SDK triggers and tasks, the SDK must be already initialized and started before receiving those events in order to be to handle them.

Initializing the MOVE SDK before[`willFinishLaunchingWithOptions`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623032-application)returns will guarantee that all the required SDK components are initialized and ready to handle the triggered system events.

{% hint style="info" %}
An exception is when it is the first time the SDK is initialized, as the host app might need to delay this step till the user is onboarded and system permission has been granted.
{% endhint %}

## Background-Fetch (recommended)

**How can you make sure that the app synchronises with the MOVE backend even if you have patches of offline operation ?**

For security reasons we cannot schedule background data upload tasks to upload data to the MOVE backend. Hence, the application must be running (at least) in the background. In order to guarantee that data is sent in a timely manner, we recommend setting up a BackgroundFetch-functionality in the app delegate of your host application.

Additionally: the background fetch is essential in case you only configure WALKING in your MOVE project. In this case, the background fetch is the only mechanism to wake up your app in the background and record WALKING data in the first place.

#### iOS 12 and below

For background fetches to work in iOS12 and below you need to implement the background fetch callback of the app delegate:

```
func application(_: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
   ...
}
```

and set the minimum background fetch interval for example in the app delegate's *didFinishLaunchingWithOptions()* with an interval of e.g. 4 hours:

```
application.setMinimumBackgroundFetchInterval(backgroundRefreshInterval)
```

#### iOS 13 and up

Follow the guide at the [Apple developer documentation.](https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app) The upload will start automatically as soon as the SDK switches into RUNNING state (SDK 1.6) respectively after initializing the SDK (SDK 2.x and higher).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/api-interface/ios/intialization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
