Initialization

API Interface / iOS

Definition

Initialize the SDK shared instance and prepare the required services based on the passed MoveConfig. 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:

func initialize(launchOptions: [UIApplication.LaunchOptionsKey: Any]?)

Parameters

launchOptions

The launch options passed inwillFinishLaunchWithOptions.

TheinitializationAPI must be executed beforewillFinishLaunchingWithOptionsreturns. We recommend calling it in didFinishLaunchingWithOptions.

Timing

Why should the initialization be called beforewillFinishLaunchingWithOptionsreturns?

Once 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 beforewillFinishLaunchingWithOptionsreturns will guarantee that all the required SDK components are initialized and ready to handle the triggered system events.

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.

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) {
   MoveSDK.shared.performBackgroundFetch(completionHandler)
}

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. 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).

Last updated