Authorizations

The SDK requires two authorizations:

Location (Always)

Motion

Background App Refresh (implicit)

By default both authorizations are requested from the user when you call start the first time.

Location

To function properly the SDK requires the ‘Always’ location permission.
If given only the ‘When-in-use’ permission the app will still track locations but will stop doing so approx. 3 min after the user closes the app (sends the app to the background).

If you want to request the permissions at another/earlier time you can do so by simply instantiating a CLLocationManager and calling requestAlwaysAuthorization at any time.

Motion

Unfortunatly, iOS provides no such way for requesting the ‘Motion authorization’ - it is automatically requested when you start gathering motion data the first time.

Background App Refresh

This is not really a permission, but needs to be handled anyway, since the user may disable this functionality within Settings -> Background App Refresh. With this setting being turned off the SDK will not function correctly. This is why we recommend implementing a notification listener as follows and display an alert if the user changes the setting:

4. Setup

This needs to be done somewhere near the top of didFinishLaunchingWithOptions. The reason is that the app may be started from the background by the system. By initializing the tracking library early, you guarantee that all location managers are set up to retreive new incoming locations.
Since the SDK may need additional time to finalize its initialization (e.g. necessary data migrations that have to be run on startup) the init call is asynchronous. The completion block will be called by the SDK once it is done with everything. Please do not call SDK functions before this block has been run since all calls will be ignored.
The library will recognize if it has already been started and act accordingly. Please be advised that if your have acquired a valid token in a previous start, you should pass it as a parameter here, otherwise pass nil. The settings parameter can also be an NSDictionary or nil. For more info see the Settings section below.

If you want to receive callbacks, set the appropriate delegate (MotionTagDelegate):

motionTag.delegate = self

To start tracking, just call the startWithToken:settings: method:

motionTag.start(withToken:"A_VALID_TOKEN", settings:SETTINGS_OR_NIL)

To checkIn/checkOut your trip and register an event with the checkIn/checkOut timestamp, call the checkIn or checkOut method:

motionTag.checkIn()
motionTag.checkOut()

To stop tracking, just call the stop method:

motionTag.stop()

Defines the business area. There are two parameters: the path to the file defining the business area as well as the distance at which you want the user to be notified when approaching the limit of the business area.

5. Settings

Both, sharedInstance(withToken: , settings: ) and start(withToken: , settings: ) accept an NSDictionary as a parameter - if you pass in nil the SDK will fall back to default values.
The settings described in this section cannot be changed while the SDK is running. So you will have stop the tracking (motionTag.stop()) before changing the settings and finally call start(withToken: , settings: ) with the modified settings to re-start the tracking. You would then also pass these modified settings into the sharedInstanceWithToken:settings:completion: method on the next start of your application - so it makes sense to persist the settings within your app.

The following options are available:

kMTDataTransferMode (MTDataTransferMode, either kDataTransferModeWifiOnly or kDataTransferMode3G; default is kDataTransferModeWifiOnly). It defines how the recorded data will be transmitted to the backend. With kDataTransferModeWifiOnly data will only be transmitted while the device has a Wifi connection. Settings the mode to kDataTransferMode3G will also allow the device to transmit data when only having a cellular connection.

kMTBatterySavingsMode (BOOL; default is true). If true MotionTag’s battery saving tracking algorithm will be used. If set to false the SDK will fall back to a standard (always running in the background) CLLocationManager startUpdatingLocation routine with a desiredAccuracy of kCLLocationAccuracyKilometer.

7. Example

API endpoints

Normally the SDK processes against MotionTag’s production backend
environment. If you need to debug and have setup staging with the
MotionTag team, you can make the SDK send data to the staging backend
by supplying the following key/value pair in your app’s
Info.plist