Quick Start

Getting Started / iOS

Check our public sample application for an actual implementation of the snippets below and how they can be utilized.

Overall Code

A quick start snippet will look something like this in your app's willFinishLaunchWithOptions:

import MoveSDK

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
 
    MoveSDK.shared.setAuthStateUpdateListener { ... }
    MoveSDK.shared.setSDKStateListener { ... }
    MoveSDK.shared.setTripStateListener { ... }
    MoveSDK.shared.setServiceFailureListener { ... }
    MoveSDK.shared.setServiceWarningListener { ... }

    MoveSDK.shared.initialize(launchOptions: launchOptions)
}

Setup

Users will be need to be authenticated. This authentication will persist until shutdown is called. It will persist over the termination of the app. The configuration to enable functionality is passed here. startAutomaticDetection will start the services. This too will be persisted and services will be automatically started when launching the app from the background.

import MoveSDK

...
let auth = MoveAuth(userToken: userToken, refreshToken: refreshToken, userID: userID, projectID: projectID)

let sdkConfig = MoveConfig(
                detectionService: [.driving([.drivingBehavior, .distractionFreeDriving]), .walking([.location]), .cycling, .places, 
                .publicTransport, .pointsOfInterest, .assistanceCall, .automaticImpactDetection)

MoveSDK.shared.setup(auth: auth, config: config)

...

MoveSDK.shared.startAutomaticDetection()
...

Let us break down the overall code block into the following:

SDK Authorization

The MoveAuth will look something like this:

let auth = MoveAuth(userToken: "", refreshToken: "", userID: "", projectID: "" )

An auth state listener must be implemented to fetch a new user token if necessary.

import MoveSDK

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

    ...

    MoveSDK.shared.setAuthStateUpdateListener { state in
        switch state {
        case .expired:
        /* you must fetch new auth object from your backend */
            MoveSDK.shared.update(auth: auth) { error in
        	/* will throw an error if sdk is not setup or userID changed */ 
            }
        }
    }

    MoveSDK.shared.initialize(launchOptions: launchOptions)

...

Authentication Expiry

SDK Configuration

MoveConfig allows host apps to configure which of the licensed Move services should be enabled. It could be based on each user preference or set from a remote server.

The MoveConfig will look something like this:

let sdkConfig = MoveConfig(
                detectionService: [.driving([.drivingBehavior, .distractionFreeDriving]), .walking([.location]), .cycling, .places, 
                .publicTransport, .pointsOfInterest, .assistanceCall, .automaticImpactDetection)

SDK State

The host app is expected to set its SDKStateListener before initializing the SDK to intercept the MoveSDKState changes caused by calling the initialize API.

The provided block could then start the SDK when MoveSDKState is ready or handle errors if occurred. The provided block could look something like this:

MoveSDK.shared.setSDKStateListener { state in
    switch state {
    case .uninitialized:
        /* SDK uninitialized*/
        break
    case .ready:
        /* SDK initialised and ready to start the service*/
        break
    case .running:
        /* SDK Started Detection*/
        break
    }
}

SDK Initialization

MoveSDK.shared.initialize(launchOptions: launchOptions)

Warnings and Errors

When services are not running properly because they are missing permissions or are not authorized on the backend, warnings or errors will be reported in the corresponding listeners.

MoveSDK.shared.setServiceFailureListener { failures in
    for failure in failures {
        /* a list of MoveServiceFailure objects */
        switch failure.reason {
	    case .unauthorized:
	        /* a service is not configured on the backend */
	        break
	    case let .missingPermission(permissions):
	        /* a required permission is missing */
	        break
        }
    }
}

MoveSDK.shared.setServiceWarningListener { warnings in
    for warning in warnings {
        /* a list of MoveServiceWarning objects */
        switch warning.reason {
	    case let .missingPermission(permissions):
	        /* an optional permission is not provided, data collection will be reduced */
	        break
        }
    }
}

Last updated

#70: add MoveSdkAndroidConfig model

Change request updated