For every Execution Taskďťż, a corresponding pre-coded module is expected in the app as part of SDK. This module executes the Task on the device running the Delivery Agent app. Thus, the Dispatcher SDK allows you to build this app with the minimum amount of effort.
The Mobile App SDK will orchestrate the execution of Tasks. Objective status updates will flow back as objective events to dispatch service through API calls made by the SDK and they will be stored in the Objective Events Store. This SDK can be used to render execution task screens on UI, maintain their states, and manage Movement Tracking Systemďťż.
Dispatch SDK is an expo-based SDK that is written in Typescript and some Modules in Java/Kotlin.
Currently supports SDK>=21 (Android).
Features
Sync Manager: Provides Sync Manager for syncing events & Docs in the background with retry functionality.
Execution Tasks: Provides a list of Execution Tasks which are as follows: Deliver, Capture Input, Deliver Cash, Complete-Success, Complete-Failure, Pickup, Doodle, Forms, Display, Verify Location, Verify OTP, Verify String, Scan QR/Barcode, Image Capture, Init Payment, Process Payment, and Complete Payment.
Execution Engine: Provides methods for Executing a given Workflow/Job in a dispatch.
Firebase Cloud Messaging: Provides a method for receiving Firebase Cloud Messaging.
Async Storage: Provides async storage for storing key-value pairs.
Higher-Order ETs: Provides a way to customize Execution Task UI.
Asynchronous Event Handling: Provides a method for handling Execution Tasks asynchronously.
1interfacesdkError{2code: string;3message: string;4}5// Error Handling from the calling Screen6React.useEffect(()=>{7if(route.params?.sdkError){8 console.log(JSON.stringify(route.params.sdkError));9 Alert.alert('Error',JSON.stringify(route.params.sdkError));10}11},[route.params?.sdkError]);1213navigation.navigate('DispatchExec',{14success:true,15objectives:[],// Pass objective List16successRoute:'SuccessScreen',17failureRoute:'FailureScreen',18initRoute:'TaskDetail',19// Calling Screen name (optional parameter). Used to throw errors back to calling screen20});
ďťż
FCM
Setup (Android only)
Add the Firebase Android configuration file to your app:
Create a Firebase project (Check Firebase instructions for creating an app).
Click Download google-services.json to obtain your Firebase Android config file (google-services.json).
Move your config file into the module (app-level) directory of your app.
To enable Firebase products in your app, add the Google services plugin to your Gradle files.
In your module (app-level) Gradle file (usually app/build.gradle), apply the Google Services Gradle plugin:
JSON
1apply plugin:'com.android.application'2// Add the following line:3apply plugin:'com.google.gms.google-services'// Google Services plugin45android {6// ...7}
ďťż
In your root-level (project-level) Gradle file (build.gradle), add rules to include the Google Services Gradle plugin. Check that you have Google's Maven repository, as well.
JS
1buildscript {23 repositories {4// Check that you have the following line (if not, add it):5google()// Google's Maven repository6}78 dependencies {9// ...1011// Add the following line:12 classpath 'com.google.gms:google-services:4.3.10'// Google Services plugin13}14}1516allprojects {17// ...1819 repositories {20// Check that you have the following line (if not, add it):21google()// Google's Maven repository22// ...23}24}
ďťż
Get FCM Token
JS
1import{2 getFCMToken,3 requestFirebasePermissions,4}from'@os1-platform/dispatch-mobile';5//Get FCM Token6let token =awaitgetFCMToken();78//Request Notifications permissions (ios)9// It will ask for user permissions for showing alert/notifications10let enabled =awaitrequestFirebasePermissions();
ďťż
Background FCM Messages
Register a callback for receiving FCM Messages in the background.
đ NOTEďťż
Call this function in the root component, i.e, in the `index.js file of the app.
useFcmMessage() custom hook in functional components to receive FCM Messages in Foreground.
JS
1import{ useFCMMessage }from'@os1-platform/dispatch-mobile';23const fcmMessage =useFCMMessage();4if(fcmMessage !=null){5// update UI here to show the message6}
ďťż
OR
Extend FCM base class in case of class components
JS
1import{FCM}from'@os1-platform/dispatch-mobile';23classClassComponentextendsFCM{4//implement these methods5handleFcmMessage(remoteMessage: object):void{}67//implement these methods8handleNotification(remoteMessage: object):void{}9}
ďťż
MTS
In the case of the dispatch mobile app, the Location Tracking module of the SDK provides a configurable way to capture and stream location data from the mobile device to the MTSďťżservice, without any user intervention. To learn more, see Dispatch Documentationďťż.
MTS Default Config
JSON
1export class MTSDefaults{2 locationFrequency: number =10000;// in milli seconds (no. of seconds after which location updates will happen)3 distanceAccuracyLimit: number =250;// in metres4 speedLimit: number =28;// in m/s5 mode: MTSMode = MTSMode.HYBRID;6 environment: MTSEnv = MTSEnv.DEV;7 batchSize: number =25;8 isMqttCleanSession: boolean =true;9 mqttKeepAliveInterval: number =15*60;//in seconds10 maxLocationAge: number =15000;// in milliseconds11 maxTraceSession: number =24*3600*100;//in milliseconds12 isOdometerEnabled: boolean =true;13 retriesBeforeFallback: number =1;14 httpFailureLimit: number =5;15 dataSendDelay: number =30000;// in milli seconds16 alarmTime: number =60000;// in milli seconds17 missingSeqCheckDuration: number =5*60*1000;// in milli seconds18 odometerPushFrequency: number =5*60*1000;// in milli seconds19 qosLevel: number =1;// values can be 0 ,120}
ďťż
Check For Mandatory MTS Permissions
JSON
1let granted = await MtsLib.requestPermissionsForMTS();2// if granted = true : all permissions granted3// granted = false : one or more permissions denied
ďťż
Init MTS
JSON
1import type { MTSInitRequest } from '@os1-platform/mts-mobile';23let mtsDefaults =newMtsLib.MTSDefaults();4mtsDefaults.speedLimit =5000;5mtsDefaults.locationFrequency =10000;6mtsDefaults.environment = MtsLib.MTSEnv.PRE_PROD;7mtsDefaults.isOdometerEnabled =false;89//Change MTS default values as per your use case1011// ...Use this for Initiating MTS12let mtsInitReq: MTSInitRequest ={13 appName:'app_name',14 appVersion:'1',15 mtsDeviceID:'deviceId',// use FCM ID here16 configData: mtsDefaults,17 baseURL:'https://{tenantId}.example.io/{mtsEndpoint}',18 accessToken:'token',19 tenantID:'TENANTID',20};21await MtsLib.initMTS(mtsInitReq);22//See Error Codes for Possible error types
ďťż
Start MTS
JSON
1let startReq: MTSStartRequest ={2 accessToken:'token',// update access token3 resetSequence:false,4 dispatchID:'12345',// pass dispatch ID here5 expiryTime: Date.now()+24*2600*1000,// expiry time after which MTS will stop automatically6};7await MtsLib.startMTS(startReq);
1PERMISSIONS_ERROR[2500]='Mandatory Android Permissions not provided';2MTS_INIT_ERROR[2501]='MTS INIT Not called! MTS Device ID is Empty';3PARAM_MISSING[2502]='Mandatory Paramater is missing in request';
ďťż
Sync Manager
Import Sync Manager
JSON
1import { AppSyncManager, SdkSyncType } from '@os1-platform/dispatch-mobile';23// Start Events sync4await AppSyncManager.getInstance().startSyncing(5false,// pass true for force sync6 SdkSyncType.EVENTS_SYNC
7);89//Start Documents sync10await AppSyncManager.getInstance().startSyncing(11false,// pass true for force sync12 SdkSyncType.DOCUMENT_SYNC
13);1415//Get All Events By Dispatch ID16await AppSyncManager.getInstance().getAllEvents('dsp_id');1718//Get all documents By Dispatch ID19await AppSyncManager.getInstance().getAllDocuments('dsp_id');
ďťż
Start Sync Manager as a Foreground Service in Android
JSON
1import { NativeSyncManager } from '@os1-platform/dispatch-mobile';23NativeSyncManager.startSyncManager(4 interval,5 notificationTitle,6 notificationText
7);8// interval will be in seconds9NativeSyncManager.startSyncManager(102000,11'Dispatch Service',12'Syncing events...'13);1415//To stop the foreground android service16NativeSyncManager.stopSyncManager();
ďťż
Asynchronous Event Handling
The Dispatch SDK support handling Execution Tasks asynchronously by emitting two events for each ET. This lets your apps to listen to these events and perform necessary actions.
For every ET, two events will be triggered in a fire-and-forget mode:
Task Start event: Triggered upon arrival of the ET, along with input data
Task End event: Triggered just before moving to the next ET, with the output data of objectives executed in that ET and the ID of the next ET to be executed.
To use this feature, you need to work with the eventListener method, which is used to listen and remove events. It contains the following methods:
.on: To listen to a specific event
.remove: To remove a specific event
JS
1eventListener ={2on(event, callback){//Add event listener and execute callback with event data }3remove(event){//Add remove event listener fn }4}
1import{ SdkUtils }from'@os1-platform/dispatch-mobile';23await SdkUtils.getRemoteConfig(3000);4// 3000 is the number of seconds to cache the config
ďťż
Download API from Public URL
JS
1/**
2 * Function to download apk file from a public URL
3 * @param apkURL - URL where apk is hosted
4 * @param version - expected version of apk (used for naming the file)
5 * @param callback - callback for getting progress of download
6 */7await SdkUtils.downloadAPK('https://apk_url.com','1',(progress)=>8 console.log(progress.totalBytesWritten)9);
ďťż
Open and Install an APK file
JS
1/**
2 * Opens & Install an APK file
3 * @param uri - source of apk file
4 */56await SdkUtils.openAPKFile(result.uri);
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key
Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key