Cordova Plugin

The following guide will help you to use the Motion-S SDK cordova plugin.

Step 1: Install the plugin

cordova platform add ios
cordova platform add android
cordova plugin add <path-to>/sdk-cordova-plugin --link -variable UseSwiftLanguageVersion=5

Step 2: Configure the SDK via configuration files

iOS

Edit the MotionSDK.plist file located in motions-sdk-corodova plugin/ios folder.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>uploadURL</key>
  <string>https://my-upload-server.lu/accepts_json?api_Key=12345</string>
  <key>uploadHeader</key>
  <dict>
    <key>Authorization</key>
    <string>Basic 12345</string>
  </dict>
  <key>tripMetadata</key>
  <dict>
    <key>Version</key>
    <string>14.4</string>
  </dict>
</dict>
</plist>

Android

Edit the MotionS.xml located in the android subfolder of the plugin.

<?xml version="1.0" encoding="utf-8"?>

<resources>
    <string name="apiKey">apikey</string>
    <string name="motions_sdk">1.0.0</string>
    <string name="url">https://api.example.com/trips</string>
    <string name="activityUrl">https://api.example.com/activities</string>
    <string name="baseUrl">https://api.motion-s.com/</string>
    <bool name="customSettings">true</bool>
    <string name="token">token</string>
    <string name="version">1.0.0</string>
    <string name="customKey"></string>
    <string name="customValue"></string>
    <bool name="activityTransition">false</bool>
</resources>

Step 3: Set Configuration Programmatically

Both the Android and the iOS site of the Cordova plugin define configuration methods to load a new runtime configuration. Use it like so:

                var devicePlatform = device.platform;
                if(devicePlatform == "iPhone" || devicePlatform == "iOS") {
                    window.cordova.plugins.motions.configureiOS('https://api.motion-s.com/upload', {"x-api-key":"1234"}, {"driver_id": "42", "foo":"bar"}, function(response) {
                    }, function(error){
                        console.log(error);
                });
                    } else {
                        window.cordova.plugins.motions.configureAndroid('https://api.motion-s.com/upload', 'https://api.motion-s.com/activities', '1234', true, "driver_id=42, foo=bar,  device_id=33", false, '3.0',  'https://api.motion-s.com/', "configureAndroid", function(response) {
                        console.log(response);
                        alert(response);
                }, function(error){
                        console.log(error);
                });
                    }

Step 4: Actions

//Initializes the SDK (if not already done) and enables trip recording
//trip monitoring/recording starts automatically with plugin load
cordova.plugins.motions.start();
//Stops the SDK / the current recording
cordova.plugins.motions.finish();
//Forces trip uploading (if not already in progress; normally this is happening periodically)
cordova.plugins.motions.syncTrips();