@os1-platform/dispatch-mobile 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/android/.gradle/7.5/fileHashes/fileHashes.lock +0 -0
  2. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  3. package/android/.idea/caches/deviceStreaming.xml +11 -0
  4. package/android/build.gradle +1 -0
  5. package/android/src/main/AndroidManifest.xml +1 -0
  6. package/android/src/main/java/com/dispatchsdk/DispatchSdkPackage.kt +5 -1
  7. package/android/src/main/java/com/dispatchsdk/location/LocationModule.kt +79 -0
  8. package/android/src/main/java/com/dispatchsdk/permissions/PermissionModule.kt +90 -0
  9. package/ios/EventEmitter.swift +13 -1
  10. package/ios/LocationManager.swift +143 -0
  11. package/ios/LocationModule.m +19 -0
  12. package/ios/LocationModule.swift +32 -0
  13. package/ios/PermissionsModule.m +21 -0
  14. package/ios/PermissionsModule.swift +24 -0
  15. package/ios/RNEventEmitter.m +2 -8
  16. package/ios/RNEventEmitter.swift +13 -19
  17. package/lib/commonjs/components/executiontasks/doodle/SignatureET.js +5 -3
  18. package/lib/commonjs/components/executiontasks/doodle/SignatureET.js.map +1 -1
  19. package/lib/commonjs/components/executiontasks/imageCapture/ImageCapture.js +5 -3
  20. package/lib/commonjs/components/executiontasks/imageCapture/ImageCapture.js.map +1 -1
  21. package/lib/commonjs/manager/location/LocationManager.js +91 -46
  22. package/lib/commonjs/manager/location/LocationManager.js.map +1 -1
  23. package/lib/commonjs/native/LocationModule.js +47 -0
  24. package/lib/commonjs/native/LocationModule.js.map +1 -0
  25. package/lib/commonjs/native/PermissionModule.js +21 -0
  26. package/lib/commonjs/native/PermissionModule.js.map +1 -0
  27. package/lib/commonjs/utils/ExecTaskUtils.js +3 -3
  28. package/lib/commonjs/utils/ExecTaskUtils.js.map +1 -1
  29. package/lib/commonjs/utils/SdkUtils.js +12 -4
  30. package/lib/commonjs/utils/SdkUtils.js.map +1 -1
  31. package/lib/module/components/executiontasks/doodle/SignatureET.js +5 -3
  32. package/lib/module/components/executiontasks/doodle/SignatureET.js.map +1 -1
  33. package/lib/module/components/executiontasks/imageCapture/ImageCapture.js +5 -3
  34. package/lib/module/components/executiontasks/imageCapture/ImageCapture.js.map +1 -1
  35. package/lib/module/manager/location/LocationManager.js +90 -44
  36. package/lib/module/manager/location/LocationManager.js.map +1 -1
  37. package/lib/module/native/LocationModule.js +41 -0
  38. package/lib/module/native/LocationModule.js.map +1 -0
  39. package/lib/module/native/PermissionModule.js +15 -0
  40. package/lib/module/native/PermissionModule.js.map +1 -0
  41. package/lib/module/utils/ExecTaskUtils.js +3 -3
  42. package/lib/module/utils/ExecTaskUtils.js.map +1 -1
  43. package/lib/module/utils/SdkUtils.js +12 -4
  44. package/lib/module/utils/SdkUtils.js.map +1 -1
  45. package/lib/typescript/manager/location/LocationManager.d.ts +4 -2
  46. package/lib/typescript/native/LocationModule.d.ts +14 -0
  47. package/lib/typescript/native/PermissionModule.d.ts +6 -0
  48. package/package.json +4 -4
  49. package/src/components/executiontasks/doodle/SignatureET.tsx +6 -4
  50. package/src/components/executiontasks/imageCapture/ImageCapture.tsx +6 -3
  51. package/src/manager/location/LocationManager.ts +93 -41
  52. package/src/native/LocationModule.ts +52 -0
  53. package/src/native/PermissionModule.ts +21 -0
  54. package/src/utils/ExecTaskUtils.ts +3 -3
  55. package/src/utils/SdkUtils.ts +15 -5
@@ -6,6 +6,7 @@ import * as Location from 'expo-location';
6
6
  import NetworkUtil from './NetworkUtil';
7
7
  import { BaseError } from '../errors/BaseError';
8
8
  import ErrorCodes from '../errors/ErrorCodes';
9
+ import PermissionModule from '../native/PermissionModule';
9
10
  const {
10
11
  DispatchSdkUtils
11
12
  } = NativeModules;
@@ -79,8 +80,13 @@ export default class SdkUtils {
79
80
  });
80
81
  }
81
82
  static async checkMandatory() {
82
- if (Platform.OS === 'ios') return;
83
- // if (Platform.OS === 'ios') return true;
83
+ if (Platform.OS === 'ios') {
84
+ const foregroundLocation = await PermissionModule.requestForegroundPermissions();
85
+ if (!foregroundLocation) {
86
+ throw new BaseError(ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED, 'Location or GPS not enabled');
87
+ }
88
+ return;
89
+ }
84
90
  const dateTimeCheck = await DispatchSdkUtils.isAutomaticDateTimeEnabled();
85
91
  if (!dateTimeCheck) {
86
92
  throw new BaseError(ErrorCodes.SYSTEM_TIME_CHECK_FAILED, 'Automatic date/time not enabled!');
@@ -88,8 +94,10 @@ export default class SdkUtils {
88
94
  if (Platform.OS === 'android') {
89
95
  await Location.enableNetworkProviderAsync();
90
96
  let locationServicesCheck = await Location.hasServicesEnabledAsync();
91
- const foregroundLocation = await Location.requestForegroundPermissionsAsync();
92
- const bgLocation = await Location.requestBackgroundPermissionsAsync();
97
+ const foregroundLocation = await PermissionModule.requestForegroundPermissions();
98
+ // await Location.requestForegroundPermissionsAsync(); //permission code using expo module
99
+ const bgLocation = await PermissionModule.requestBackgroundPermissions();
100
+ // await Location.requestBackgroundPermissionsAsync(); //permission code using expo module
93
101
  if (!(locationServicesCheck && foregroundLocation && bgLocation)) {
94
102
  throw new BaseError(ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED, 'Location or GPS not enabled');
95
103
  }
@@ -1 +1 @@
1
- {"version":3,"names":["remoteConfig","Logger","LOG_TYPE","FileSystem","NativeModules","Platform","Location","NetworkUtil","BaseError","ErrorCodes","DispatchSdkUtils","DispatchUtilsInterface","SdkUtils","getRemoteConfig","expiration","Promise","resolve","reject","fetch","setDefaults","cxRumDevApiKey","cxRumProdApiKey","isMandatoryUpdate","isMandatoryUpdateiOS","toggleInAppUpdateiOS","toggleInAppUpdate","then","fetchAndActivate","fetchedRemotely","config","getAll","getInstance","logEvent","SDK_INFO","catch","err","error","downloadAPK","apkURL","version","callback","fileUri","cacheDirectory","fileInfo","getInfoAsync","currentDate","Date","toLocaleDateString","fileDate","modificationTime","exists","uri","downloadResumable","createDownloadResumable","downloadResult","downloadAsync","deleteApk","deleteAsync","openAPKFile","openAndInstallApk","openAppSettings","openSettings","message","SDK_ERROR","checkMandatory","OS","dateTimeCheck","isAutomaticDateTimeEnabled","SYSTEM_TIME_CHECK_FAILED","enableNetworkProviderAsync","locationServicesCheck","hasServicesEnabledAsync","foregroundLocation","requestForegroundPermissionsAsync","bgLocation","requestBackgroundPermissionsAsync","LOCATION_OR_GPS_NOT_ENABLED","internet","isAvailableAsync","INTERNET_NOT_ENABLED"],"sources":["SdkUtils.ts"],"sourcesContent":["import remoteConfig from '@react-native-firebase/remote-config';\nimport Logger, { LOG_TYPE } from './Logger';\nimport type { DownloadProgressData } from 'expo-file-system';\nimport * as FileSystem from 'expo-file-system';\nimport { NativeModules, Platform } from 'react-native';\nimport * as Location from 'expo-location';\nimport NetworkUtil from './NetworkUtil';\nimport { BaseError } from '../errors/BaseError';\nimport ErrorCodes from '../errors/ErrorCodes';\n\nconst { DispatchSdkUtils } = NativeModules;\n\ninterface DispatchUtilsInterface {\n openAndInstallApk(apkUri: String): Promise<boolean>;\n openSettings(): Promise<boolean>;\n showAndroidDialog(\n title: string,\n message: string,\n positiveText: string,\n negativeText: string | null,\n cancelable: boolean\n ): Promise<boolean>;\n isAutomaticDateTimeEnabled(): Promise<boolean>;\n}\n\nexport { DispatchSdkUtils as DispatchUtilsInterface };\n\nexport default class SdkUtils {\n /**\n * number of seconds to cache the firebase config\n * @param expiration\n */\n static async getRemoteConfig(expiration: number): Promise<any> {\n return new Promise(async (resolve, reject) => {\n try {\n await remoteConfig().fetch(expiration);\n remoteConfig()\n .setDefaults({\n cxRumDevApiKey: 'NA',\n cxRumProdApiKey: 'NA',\n isMandatoryUpdate: 'false',\n isMandatoryUpdateiOS: 'false',\n toggleInAppUpdateiOS: 'false',\n toggleInAppUpdate: 'false',\n })\n .then(() => remoteConfig().fetchAndActivate())\n .then((fetchedRemotely) => {\n let config = remoteConfig().getAll();\n if (fetchedRemotely) {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'Configs were retrieved from the backend and activated.',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n } else {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'No configs were fetched from the backend, and the local configs were already activated',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n }\n })\n .catch((err) => {\n reject(err);\n });\n } catch (error: any) {\n reject(error);\n }\n });\n }\n\n /**\n * Function to download apk file from a public URL\n * @param apkURL - URL where apk is hosted\n * @param version - expected version of apk (used for naming the file)\n * @param callback - callback for getting progress of download\n */\n public static async downloadAPK(\n apkURL: string,\n version: string,\n callback: (progress: DownloadProgressData) => any\n ): Promise<string | undefined> {\n const fileUri = FileSystem.cacheDirectory + `${version}.apk`;\n const fileInfo = await FileSystem.getInfoAsync(fileUri);\n const currentDate = new Date().toLocaleDateString();\n const fileDate = new Date(\n fileInfo.modificationTime ? fileInfo.modificationTime * 1000 : 0\n ).toLocaleDateString();\n if (fileInfo.exists && currentDate === fileDate) {\n return fileInfo.uri;\n }\n const downloadResumable = FileSystem.createDownloadResumable(\n apkURL,\n FileSystem.cacheDirectory + `${version}.apk`,\n {},\n callback\n );\n const downloadResult = await downloadResumable.downloadAsync();\n return downloadResult?.uri;\n }\n\n /**\n * Opens & Install an APK file\n * @param uri - source of apk file\n */\n public static async deleteApk(version: string) {\n await FileSystem.deleteAsync(FileSystem.cacheDirectory + `${version}.apk`);\n }\n\n public static async openAPKFile(uri: string) {\n return await (DispatchSdkUtils as DispatchUtilsInterface).openAndInstallApk(\n uri\n );\n }\n\n public static openAppSettings() {\n (DispatchSdkUtils as DispatchUtilsInterface)\n .openSettings()\n .then()\n .catch((error) => {\n Logger.getInstance().logEvent(\n 'Intent error',\n error.message,\n LOG_TYPE.SDK_ERROR\n );\n });\n }\n\n public static async checkMandatory() {\n if (Platform.OS === 'ios') return;\n // if (Platform.OS === 'ios') return true;\n const dateTimeCheck = await (\n DispatchSdkUtils as DispatchUtilsInterface\n ).isAutomaticDateTimeEnabled();\n if (!dateTimeCheck) {\n throw new BaseError(\n ErrorCodes.SYSTEM_TIME_CHECK_FAILED,\n 'Automatic date/time not enabled!'\n );\n }\n if (Platform.OS === 'android') {\n await Location.enableNetworkProviderAsync();\n let locationServicesCheck = await Location.hasServicesEnabledAsync();\n const foregroundLocation =\n await Location.requestForegroundPermissionsAsync();\n const bgLocation = await Location.requestBackgroundPermissionsAsync();\n if (!(locationServicesCheck && foregroundLocation && bgLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n }\n let internet = await NetworkUtil.isAvailableAsync();\n if (!internet)\n throw new BaseError(\n ErrorCodes.INTERNET_NOT_ENABLED,\n 'Internet is disabled! Please enable internet and try again '\n );\n }\n}\n"],"mappings":"AAAA,OAAOA,YAAY,MAAM,sCAAsC;AAC/D,OAAOC,MAAM,IAAIC,QAAQ,QAAQ,UAAU;AAE3C,OAAO,KAAKC,UAAU,MAAM,kBAAkB;AAC9C,SAASC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,OAAO,KAAKC,QAAQ,MAAM,eAAe;AACzC,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,OAAOC,UAAU,MAAM,sBAAsB;AAE7C,MAAM;EAAEC;AAAiB,CAAC,GAAGN,aAAa;AAe1C,SAASM,gBAAgB,IAAIC,sBAAsB;AAEnD,eAAe,MAAMC,QAAQ,CAAC;EAC5B;AACF;AACA;AACA;EACE,aAAaC,eAAeA,CAACC,UAAkB,EAAgB;IAC7D,OAAO,IAAIC,OAAO,CAAC,OAAOC,OAAO,EAAEC,MAAM,KAAK;MAC5C,IAAI;QACF,MAAMjB,YAAY,CAAC,CAAC,CAACkB,KAAK,CAACJ,UAAU,CAAC;QACtCd,YAAY,CAAC,CAAC,CACXmB,WAAW,CAAC;UACXC,cAAc,EAAE,IAAI;UACpBC,eAAe,EAAE,IAAI;UACrBC,iBAAi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IAAI1D,SAAS,CACjBC,UAAU,CAAC2D,wBAAwB,EACnC,kCACF,CAAC;IACH;IACA,IAAI/D,QAAQ,CAAC4D,EAAE,KAAK,SAAS,EAAE;MAC7B,MAAM3D,QAAQ,CAAC+D,0BAA0B,CAAC,CAAC;MAC3C,IAAIC,qBAAqB,GAAG,MAAMhE,QAAQ,CAACiE,uBAAuB,CAAC,CAAC;MACpE,MAAMC,kBAAkB,GACtB,MAAMlE,QAAQ,CAACmE,iCAAiC,CAAC,CAAC;MACpD,MAAMC,UAAU,GAAG,MAAMpE,QAAQ,CAACqE,iCAAiC,CAAC,CAAC;MACrE,IAAI,EAAEL,qBAAqB,IAAIE,kBAAkB,IAAIE,UAAU,CAAC,EAAE;QAChE,MAAM,IAAIlE,SAAS,CACjBC,UAAU,CAACmE,2BAA2B,EACtC,6BACF,CAAC;MACH;IACF;IACA,IAAIC,QAAQ,GAAG,MAAMtE,WAAW,CAACuE,gBAAgB,CAAC,CAAC;IACnD,IAAI,CAACD,QAAQ,EACX,MAAM,IAAIrE,SAAS,CACjBC,UAAU,CAACsE,oBAAoB,EAC/B,6DACF,CAAC;EACL;AACF","ignoreList":[]}
1
+ {"version":3,"names":["remoteConfig","Logger","LOG_TYPE","FileSystem","NativeModules","Platform","Location","NetworkUtil","BaseError","ErrorCodes","PermissionModule","DispatchSdkUtils","DispatchUtilsInterface","SdkUtils","getRemoteConfig","expiration","Promise","resolve","reject","fetch","setDefaults","cxRumDevApiKey","cxRumProdApiKey","isMandatoryUpdate","isMandatoryUpdateiOS","toggleInAppUpdateiOS","toggleInAppUpdate","then","fetchAndActivate","fetchedRemotely","config","getAll","getInstance","logEvent","SDK_INFO","catch","err","error","downloadAPK","apkURL","version","callback","fileUri","cacheDirectory","fileInfo","getInfoAsync","currentDate","Date","toLocaleDateString","fileDate","modificationTime","exists","uri","downloadResumable","createDownloadResumable","downloadResult","downloadAsync","deleteApk","deleteAsync","openAPKFile","openAndInstallApk","openAppSettings","openSettings","message","SDK_ERROR","checkMandatory","OS","foregroundLocation","requestForegroundPermissions","LOCATION_OR_GPS_NOT_ENABLED","dateTimeCheck","isAutomaticDateTimeEnabled","SYSTEM_TIME_CHECK_FAILED","enableNetworkProviderAsync","locationServicesCheck","hasServicesEnabledAsync","bgLocation","requestBackgroundPermissions","internet","isAvailableAsync","INTERNET_NOT_ENABLED"],"sources":["SdkUtils.ts"],"sourcesContent":["import remoteConfig from '@react-native-firebase/remote-config';\nimport Logger, { LOG_TYPE } from './Logger';\nimport type { DownloadProgressData } from 'expo-file-system';\nimport * as FileSystem from 'expo-file-system';\nimport { NativeModules, Platform } from 'react-native';\nimport * as Location from 'expo-location';\nimport NetworkUtil from './NetworkUtil';\nimport { BaseError } from '../errors/BaseError';\nimport ErrorCodes from '../errors/ErrorCodes';\nimport PermissionModule from '../native/PermissionModule';\n\nconst { DispatchSdkUtils } = NativeModules;\n\ninterface DispatchUtilsInterface {\n openAndInstallApk(apkUri: String): Promise<boolean>;\n openSettings(): Promise<boolean>;\n showAndroidDialog(\n title: string,\n message: string,\n positiveText: string,\n negativeText: string | null,\n cancelable: boolean\n ): Promise<boolean>;\n isAutomaticDateTimeEnabled(): Promise<boolean>;\n}\n\nexport { DispatchSdkUtils as DispatchUtilsInterface };\n\nexport default class SdkUtils {\n /**\n * number of seconds to cache the firebase config\n * @param expiration\n */\n static async getRemoteConfig(expiration: number): Promise<any> {\n return new Promise(async (resolve, reject) => {\n try {\n await remoteConfig().fetch(expiration);\n remoteConfig()\n .setDefaults({\n cxRumDevApiKey: 'NA',\n cxRumProdApiKey: 'NA',\n isMandatoryUpdate: 'false',\n isMandatoryUpdateiOS: 'false',\n toggleInAppUpdateiOS: 'false',\n toggleInAppUpdate: 'false',\n })\n .then(() => remoteConfig().fetchAndActivate())\n .then((fetchedRemotely) => {\n let config = remoteConfig().getAll();\n if (fetchedRemotely) {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'Configs were retrieved from the backend and activated.',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n } else {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'No configs were fetched from the backend, and the local configs were already activated',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n }\n })\n .catch((err) => {\n reject(err);\n });\n } catch (error: any) {\n reject(error);\n }\n });\n }\n\n /**\n * Function to download apk file from a public URL\n * @param apkURL - URL where apk is hosted\n * @param version - expected version of apk (used for naming the file)\n * @param callback - callback for getting progress of download\n */\n public static async downloadAPK(\n apkURL: string,\n version: string,\n callback: (progress: DownloadProgressData) => any\n ): Promise<string | undefined> {\n const fileUri = FileSystem.cacheDirectory + `${version}.apk`;\n const fileInfo = await FileSystem.getInfoAsync(fileUri);\n const currentDate = new Date().toLocaleDateString();\n const fileDate = new Date(\n fileInfo.modificationTime ? fileInfo.modificationTime * 1000 : 0\n ).toLocaleDateString();\n if (fileInfo.exists && currentDate === fileDate) {\n return fileInfo.uri;\n }\n const downloadResumable = FileSystem.createDownloadResumable(\n apkURL,\n FileSystem.cacheDirectory + `${version}.apk`,\n {},\n callback\n );\n const downloadResult = await downloadResumable.downloadAsync();\n return downloadResult?.uri;\n }\n\n /**\n * Opens & Install an APK file\n * @param uri - source of apk file\n */\n public static async deleteApk(version: string) {\n await FileSystem.deleteAsync(FileSystem.cacheDirectory + `${version}.apk`);\n }\n\n public static async openAPKFile(uri: string) {\n return await (DispatchSdkUtils as DispatchUtilsInterface).openAndInstallApk(\n uri\n );\n }\n\n public static openAppSettings() {\n (DispatchSdkUtils as DispatchUtilsInterface)\n .openSettings()\n .then()\n .catch((error) => {\n Logger.getInstance().logEvent(\n 'Intent error',\n error.message,\n LOG_TYPE.SDK_ERROR\n );\n });\n }\n\n public static async checkMandatory() {\n if (Platform.OS === 'ios'){\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n if (!(foregroundLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n return;\n }\n const dateTimeCheck = await (\n DispatchSdkUtils as DispatchUtilsInterface\n ).isAutomaticDateTimeEnabled();\n if (!dateTimeCheck) {\n throw new BaseError(\n ErrorCodes.SYSTEM_TIME_CHECK_FAILED,\n 'Automatic date/time not enabled!'\n );\n }\n if (Platform.OS === 'android') {\n await Location.enableNetworkProviderAsync();\n let locationServicesCheck = await Location.hasServicesEnabledAsync();\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n // await Location.requestForegroundPermissionsAsync(); //permission code using expo module\n const bgLocation = await PermissionModule.requestBackgroundPermissions();\n // await Location.requestBackgroundPermissionsAsync(); //permission code using expo module\n if (!(locationServicesCheck && foregroundLocation && bgLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n }\n let internet = await NetworkUtil.isAvailableAsync();\n if (!internet)\n throw new BaseError(\n ErrorCodes.INTERNET_NOT_ENABLED,\n 'Internet is disabled! Please enable internet and try again '\n );\n }\n}\n"],"mappings":"AAAA,OAAOA,YAAY,MAAM,sCAAsC;AAC/D,OAAOC,MAAM,IAAIC,QAAQ,QAAQ,UAAU;AAE3C,OAAO,KAAKC,UAAU,MAAM,kBAAkB;AAC9C,SAASC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,OAAO,KAAKC,QAAQ,MAAM,eAAe;AACzC,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,OAAOC,UAAU,MAAM,sBAAsB;AAC7C,OAAOC,gBAAgB,MAAM,4BAA4B;AAEzD,MAAM;EAAEC;AAAiB,CAAC,GAAGP,aAAa;AAe1C,SAASO,gBAAgB,IAAIC,sBAAsB;AAEnD,eAAe,MAAMC,QAAQ,CAAC;EAC5B;AACF;AACA;AACA;EACE,aAAaC,eAAeA,CAACC,UAAkB,EAAgB;IAC7D,OAAO,IAAIC,OAAO,CAAC,OAAOC,OAAO,EAAEC,MAAM,KAAK;MAC5C,IAAI;QACF,MAAM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,QAAQ,CAAC6D,EAAE,KAAK,KAAK,EAAC;MACxB,MAAMC,kBAAkB,GAAG,MAAMzD,gBAAgB,CAAC0D,4BAA4B,CAAC,CAAC;MAChF,IAAI,CAAED,kBAAmB,EAAE;QACzB,MAAM,IAAI3D,SAAS,CACjBC,UAAU,CAAC4D,2BAA2B,EACtC,6BACF,CAAC;MACH;MACA;IACF;IACA,MAAMC,aAAa,GAAG,MACpB3D,gBAAgB,CAChB4D,0BAA0B,CAAC,CAAC;IAC9B,IAAI,CAACD,aAAa,EAAE;MAClB,MAAM,IAAI9D,SAAS,CACjBC,UAAU,CAAC+D,wBAAwB,EACnC,kCACF,CAAC;IACH;IACA,IAAInE,QAAQ,CAAC6D,EAAE,KAAK,SAAS,EAAE;MAC7B,MAAM5D,QAAQ,CAACmE,0BAA0B,CAAC,CAAC;MAC3C,IAAIC,qBAAqB,GAAG,MAAMpE,QAAQ,CAACqE,uBAAuB,CAAC,CAAC;MACpE,MAAMR,kBAAkB,GAAG,MAAMzD,gBAAgB,CAAC0D,4BAA4B,CAAC,CAAC;MAChF;MACA,MAAMQ,UAAU,GAAG,MAAMlE,gBAAgB,CAACmE,4BAA4B,CAAC,CAAC;MACxE;MACA,IAAI,EAAEH,qBAAqB,IAAIP,kBAAkB,IAAIS,UAAU,CAAC,EAAE;QAChE,MAAM,IAAIpE,SAAS,CACjBC,UAAU,CAAC4D,2BAA2B,EACtC,6BACF,CAAC;MACH;IACF;IACA,IAAIS,QAAQ,GAAG,MAAMvE,WAAW,CAACwE,gBAAgB,CAAC,CAAC;IACnD,IAAI,CAACD,QAAQ,EACX,MAAM,IAAItE,SAAS,CACjBC,UAAU,CAACuE,oBAAoB,EAC/B,6DACF,CAAC;EACL;AACF","ignoreList":[]}
@@ -1,11 +1,13 @@
1
1
  export default class LocationManager {
2
2
  private static instance;
3
- private lastLocation;
3
+ private lastLocationAndroid;
4
+ private lastLocationiOS;
4
5
  private stopUpdate;
6
+ private subscription;
5
7
  checkForLocationPermissions(): Promise<boolean>;
6
8
  static getInstance(): LocationManager;
7
9
  startUpdates(): void;
8
- getLastLocation(): DLocation;
10
+ getLastLocation(): Promise<DLocation>;
9
11
  stopLocationUpdates(): void;
10
12
  }
11
13
  export interface DLocation {
@@ -0,0 +1,14 @@
1
+ import { EmitterSubscription } from 'react-native';
2
+ export interface LocationType {
3
+ latitude: number;
4
+ longitude: number;
5
+ accuracy: number;
6
+ }
7
+ declare const _default: {
8
+ startLocationUpdates: () => Promise<void>;
9
+ stopLocationUpdates: () => Promise<void>;
10
+ addLocationListener: (callback: (location: LocationType) => void) => EmitterSubscription;
11
+ removeLocationListener: (subscription: EmitterSubscription) => void;
12
+ getLastLocation: () => Promise<any>;
13
+ };
14
+ export default _default;
@@ -0,0 +1,6 @@
1
+ interface PermissionsModuleType {
2
+ requestForegroundPermissions: () => Promise<boolean>;
3
+ requestBackgroundPermissions: () => Promise<boolean>;
4
+ }
5
+ declare const _default: PermissionsModuleType;
6
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@os1-platform/dispatch-mobile",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Dispatch SDK React Native Package",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -50,7 +50,7 @@
50
50
  "license": "MIT",
51
51
  "author": "Amit Sanvedi <amit.sanvedi@delhivery.com> (https://github.com/FoxtrotPlatform/platform-coreos-dispatch-sdk)",
52
52
  "homepage": "https://github.com/FoxtrotPlatform/platform-coreos-dispatch-sdk/#readme",
53
- "devDependencies": {
53
+ "devDependencies": {
54
54
  "@apollo/client": "^3.5.6",
55
55
  "@babel/core": "^7.12.9",
56
56
  "@babel/preset-env": "^7.15.8",
@@ -256,7 +256,7 @@
256
256
  ]
257
257
  ]
258
258
  },
259
- "dependencies": {
259
+ "dependencies": {
260
260
  "@os1-platform/platform-coreos-execution-engine-sdk": "1.0.17",
261
261
  "@rjsf/core": "^2.0.0",
262
262
  "apollo-link-timeout": "^4.0.0",
@@ -275,4 +275,4 @@
275
275
  "rjsf-native": "^1.0.14",
276
276
  "toggle-switch-react-native": "^3.3.0"
277
277
  }
278
- }
278
+ }
@@ -143,10 +143,12 @@ lineHeight: 24 }}>{props.title}</Text>
143
143
  )) ?? 'NULL';
144
144
  const dateTime = await callbackHandler.getDateTime();
145
145
  console.log('saveAndSubmit:dateTime: ', dateTime);
146
-
147
- let lat = LocationManager.getInstance().getLastLocation().latitude;
148
- let lng = LocationManager.getInstance().getLastLocation().longitude;
149
- let accuracy = LocationManager.getInstance().getLastLocation().accuracy;
146
+ let lastLocation = await LocationManager.getInstance().getLastLocation();
147
+ console.log("signatureET:lastLocation:",JSON.stringify(lastLocation));
148
+
149
+ let lat = lastLocation.latitude;
150
+ let lng = lastLocation.longitude;
151
+ let accuracy = lastLocation.accuracy;
150
152
 
151
153
  let insertID = await insertDocumentInDB(
152
154
  fileName,
@@ -304,6 +304,9 @@ const ImageCapture = (props: any) => {
304
304
  imgArray = imagesDummy;
305
305
  const dateTime = await callbackHandler.getDateTime();
306
306
  console.log('captureImage:dateTime: ', dateTime);
307
+ let lastLocation = await LocationManager.getInstance().getLastLocation();
308
+ console.log("captureImage:lastLocation:",JSON.stringify(lastLocation));
309
+
307
310
  imgArray[index] = {
308
311
  id: CaptureUtils.getImagesFileName(),
309
312
  // @ts-ignore
@@ -311,9 +314,9 @@ const ImageCapture = (props: any) => {
311
314
  url: '',
312
315
  timestamp: Date.now(),
313
316
  dateTime: dateTime,
314
- lat: LocationManager.getInstance().getLastLocation().latitude,
315
- lng: LocationManager.getInstance().getLastLocation().longitude,
316
- accuracy: LocationManager.getInstance().getLastLocation().accuracy,
317
+ lat: lastLocation.latitude,
318
+ lng: lastLocation.longitude,
319
+ accuracy: lastLocation.accuracy,
317
320
  };
318
321
  setImagesDummy([...imgArray])
319
322
  console.log("images211:", JSON.stringify(imgArray));
@@ -1,20 +1,37 @@
1
1
  import * as Location from 'expo-location';
2
2
  import { Accuracy, LocationObject } from 'expo-location';
3
3
  import Logger, { LOG_TYPE } from '../../utils/Logger';
4
+ import { EmitterSubscription, Platform } from 'react-native';
5
+ import PermissionModule from '../../native/PermissionModule';
6
+ import LocationModule, { LocationType } from '../../native/LocationModule';
4
7
 
5
8
  export default class LocationManager {
6
9
  private static instance: LocationManager;
7
- private lastLocation: LocationObject | null = null;
10
+ private lastLocationAndroid: LocationType | null = null;
11
+ private lastLocationiOS: LocationType | null = null;
8
12
  private stopUpdate: { remove(): void } | undefined;
13
+ private subscription: EmitterSubscription | null = null;
9
14
 
10
15
  public async checkForLocationPermissions(): Promise<boolean> {
11
- let permissionResponse = await Location.getForegroundPermissionsAsync();
12
- if (permissionResponse.status === 'granted') {
13
- this.startUpdates();
14
- return true;
15
- } else {
16
- let { status } = await Location.requestForegroundPermissionsAsync();
17
- if (status === 'granted') {
16
+ console.log("checkForLocationPermissions");
17
+ if (Platform.OS === 'ios') {
18
+ // old code checking for permissions using expo-location
19
+ // let permissionResponse = await Location.getForegroundPermissionsAsync();
20
+ // if (permissionResponse.status === 'granted') {
21
+ // this.startUpdates();
22
+ // return true;
23
+ // } else {
24
+ // let { status } = await Location.requestForegroundPermissionsAsync();
25
+ // if (status === 'granted') {
26
+ // this.startUpdates();
27
+ // return true;
28
+ // } else {
29
+ // this.stopLocationUpdates();
30
+ // return false;
31
+ // }
32
+ // }
33
+ let foregroundPermission = await PermissionModule.requestForegroundPermissions();
34
+ if (foregroundPermission) {
18
35
  this.startUpdates();
19
36
  return true;
20
37
  } else {
@@ -22,6 +39,17 @@ export default class LocationManager {
22
39
  return false;
23
40
  }
24
41
  }
42
+ if (Platform.OS === 'android') {
43
+ let foregroundPermission = await PermissionModule.requestForegroundPermissions();
44
+ if (foregroundPermission) {
45
+ this.startUpdates();
46
+ return true;
47
+ } else {
48
+ this.stopLocationUpdates();
49
+ return false;
50
+ }
51
+ }
52
+ return true;
25
53
  }
26
54
 
27
55
  public static getInstance(): LocationManager {
@@ -30,50 +58,74 @@ export default class LocationManager {
30
58
  }
31
59
  return LocationManager.instance;
32
60
  }
61
+
33
62
  public startUpdates() {
34
- Location.watchPositionAsync(
35
- {
36
- accuracy: Accuracy.Highest,
37
- timeInterval: 10000, // in millis
38
- distanceInterval: 10, //in metres
39
- },
40
- (location) => {
63
+ if (Platform.OS === 'android') {
64
+ LocationModule.startLocationUpdates();
65
+ this.subscription = LocationModule.addLocationListener((location) => {
66
+ console.log('Location updated:', location);
41
67
  if (location != null) {
42
- this.lastLocation = location;
68
+ this.lastLocationAndroid = location
43
69
  }
44
- }
45
- )
46
- .then((r) => {
47
- this.stopUpdate = r;
48
- })
49
- .catch((error) => {
50
- Logger.getInstance().logEvent(
51
- 'LOCATION_MANAGER',
52
- error.message,
53
- LOG_TYPE.SDK_WARNING
54
- );
55
70
  });
71
+ }
72
+
73
+ if (Platform.OS === 'ios') {
74
+ console.log("startUpdates");
75
+ LocationModule.startLocationUpdates();
76
+ // this.subscription = LocationModule.addLocationListener((location) => {
77
+ // console.log('Location updated:', location);
78
+ // if (location != null) {
79
+ // this.lastLocationiOS = location
80
+ // }
81
+ // });
82
+ }
56
83
  }
57
- public getLastLocation(): DLocation {
58
- if (this.lastLocation != null && this.lastLocation.coords != null) {
59
- let accuracy = '';
60
- if (this.lastLocation.coords.accuracy !== null) {
61
- let accuracyVal = Math.round(this.lastLocation.coords.accuracy);
62
- accuracy = accuracyVal.toString();
63
- }
84
+
85
+ public async getLastLocation(): Promise<DLocation> {
86
+ if (Platform.OS === 'android' && this.lastLocationAndroid != null) {
87
+ console.log("lastLocationAndroid:", this.lastLocationAndroid);
64
88
  return {
65
- latitude: this.lastLocation.coords.latitude.toString(),
66
- longitude: this.lastLocation.coords.longitude.toString(),
67
- accuracy: accuracy,
89
+ latitude: this.lastLocationAndroid.latitude.toString(),
90
+ longitude: this.lastLocationAndroid.longitude.toString(),
91
+ accuracy: this.lastLocationAndroid.accuracy.toString(),
68
92
  };
69
- } else {
70
- return { latitude: 'null', longitude: 'null', accuracy: 'null' };
71
93
  }
94
+ if (Platform.OS === 'ios') {
95
+ this.lastLocationiOS = await LocationModule.getLastLocation();
96
+ console.log("lastLocationiOS:", this.lastLocationiOS);
97
+ if(this.lastLocationiOS){
98
+ return {
99
+ latitude: this.lastLocationiOS.latitude.toString(),
100
+ longitude: this.lastLocationiOS.longitude.toString(),
101
+ accuracy: this.lastLocationiOS.accuracy.toString(),
102
+ };
103
+ }
104
+ }
105
+ return {
106
+ latitude: 'null',
107
+ longitude: 'null',
108
+ accuracy: 'null',
109
+ };
72
110
  }
111
+
112
+
73
113
  public stopLocationUpdates() {
74
114
  try {
75
- if (this.stopUpdate) this.stopUpdate.remove();
76
- } catch (error: any) {}
115
+ // code for android
116
+ if (Platform.OS === 'android') {
117
+ if (this.subscription) {
118
+ LocationModule.removeLocationListener(this.subscription);
119
+ }
120
+ }
121
+
122
+ // code for ios
123
+ if (Platform.OS === 'ios') {
124
+ if (this.subscription) {
125
+ LocationModule.removeLocationListener(this.subscription);
126
+ }
127
+ }
128
+ } catch (error: any) { }
77
129
  }
78
130
  }
79
131
 
@@ -0,0 +1,52 @@
1
+ import { NativeModules, NativeEventEmitter, EmitterSubscription } from 'react-native';
2
+
3
+ const { LocationModule } = NativeModules;
4
+ const locationEventEmitter = new NativeEventEmitter(LocationModule);
5
+
6
+ const startLocationUpdates = async (): Promise<void> => {
7
+ try {
8
+ await LocationModule.startLocationUpdates();
9
+ } catch (error) {
10
+ console.error(error);
11
+ }
12
+ };
13
+
14
+ const stopLocationUpdates = async (): Promise<void> => {
15
+ try {
16
+ await LocationModule.stopLocationUpdates();
17
+ } catch (error) {
18
+ console.error(error);
19
+ }
20
+ };
21
+
22
+ const getLastLocation = async (): Promise<any> => {
23
+ try {
24
+ return LocationModule.getLastLocation();
25
+ } catch (error) {
26
+ console.error(error);
27
+ return null
28
+ }
29
+ }
30
+
31
+
32
+ export interface LocationType {
33
+ latitude: number;
34
+ longitude: number;
35
+ accuracy: number;
36
+ }
37
+
38
+ const addLocationListener = (callback: (location: LocationType) => void): EmitterSubscription => {
39
+ return locationEventEmitter.addListener('locationUpdated', callback);
40
+ };
41
+
42
+ const removeLocationListener = (subscription: EmitterSubscription): void => {
43
+ subscription.remove();
44
+ };
45
+
46
+ export default {
47
+ startLocationUpdates,
48
+ stopLocationUpdates,
49
+ addLocationListener,
50
+ removeLocationListener,
51
+ getLastLocation,
52
+ };
@@ -0,0 +1,21 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ const { PermissionsModule } = NativeModules;
4
+
5
+ interface PermissionsModuleType {
6
+ requestForegroundPermissions: () => Promise<boolean>;
7
+ requestBackgroundPermissions: () => Promise<boolean>;
8
+ }
9
+
10
+ const requestForegroundPermissions = async (): Promise<boolean> => {
11
+ return PermissionsModule.requestForegroundPermissions();
12
+ };
13
+
14
+ const requestBackgroundPermissions = async (): Promise<boolean> => {
15
+ return PermissionsModule.requestBackgroundPermissions();
16
+ };
17
+
18
+ export default {
19
+ requestForegroundPermissions,
20
+ requestBackgroundPermissions,
21
+ } as PermissionsModuleType;
@@ -19,7 +19,7 @@ export async function getBaseETResponse(
19
19
  mergedObjectiveIds: Array<string>,
20
20
  taskId: ExecutionTaskID
21
21
  ): Promise<BaseETResponse> {
22
- let lastLocation = LocationManager.getInstance().getLastLocation();
22
+ let lastLocation = await LocationManager.getInstance().getLastLocation();
23
23
  console.log("getBaseETResponse:lastLocation:",JSON.stringify(lastLocation))
24
24
 
25
25
  let cache = DispatchSdkCache.getInstance();
@@ -146,12 +146,12 @@ export function onTaskStart(
146
146
  const keys = DispatchSdkCache.KEYS;
147
147
  const cache = DispatchSdkCache.getInstance();
148
148
  (async () => {
149
- let lastLocation = LocationManager.getInstance().getLastLocation();
149
+ let lastLocation = await LocationManager.getInstance().getLastLocation();
150
+ console.log("onTaskStart:lastLocation:",JSON.stringify(lastLocation));
150
151
  let location = {
151
152
  latitude: lastLocation.latitude,
152
153
  longitude: lastLocation.longitude,
153
154
  }
154
- console.log("onTaskStart:lastLocation:",location)
155
155
  await cache.setKeyInCache(keys.TASK_START_TIME, Date.now().toString());
156
156
  await cache.setKeyInCache(keys.CURRENT_WORKING_TASK_ID, eventData.taskId);
157
157
  await cache.setObjectInCache(keys.TASK_START_LOCATION, location);
@@ -7,6 +7,7 @@ import * as Location from 'expo-location';
7
7
  import NetworkUtil from './NetworkUtil';
8
8
  import { BaseError } from '../errors/BaseError';
9
9
  import ErrorCodes from '../errors/ErrorCodes';
10
+ import PermissionModule from '../native/PermissionModule';
10
11
 
11
12
  const { DispatchSdkUtils } = NativeModules;
12
13
 
@@ -129,8 +130,16 @@ export default class SdkUtils {
129
130
  }
130
131
 
131
132
  public static async checkMandatory() {
132
- if (Platform.OS === 'ios') return;
133
- // if (Platform.OS === 'ios') return true;
133
+ if (Platform.OS === 'ios'){
134
+ const foregroundLocation = await PermissionModule.requestForegroundPermissions();
135
+ if (!(foregroundLocation)) {
136
+ throw new BaseError(
137
+ ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,
138
+ 'Location or GPS not enabled'
139
+ );
140
+ }
141
+ return;
142
+ }
134
143
  const dateTimeCheck = await (
135
144
  DispatchSdkUtils as DispatchUtilsInterface
136
145
  ).isAutomaticDateTimeEnabled();
@@ -143,9 +152,10 @@ export default class SdkUtils {
143
152
  if (Platform.OS === 'android') {
144
153
  await Location.enableNetworkProviderAsync();
145
154
  let locationServicesCheck = await Location.hasServicesEnabledAsync();
146
- const foregroundLocation =
147
- await Location.requestForegroundPermissionsAsync();
148
- const bgLocation = await Location.requestBackgroundPermissionsAsync();
155
+ const foregroundLocation = await PermissionModule.requestForegroundPermissions();
156
+ // await Location.requestForegroundPermissionsAsync(); //permission code using expo module
157
+ const bgLocation = await PermissionModule.requestBackgroundPermissions();
158
+ // await Location.requestBackgroundPermissionsAsync(); //permission code using expo module
149
159
  if (!(locationServicesCheck && foregroundLocation && bgLocation)) {
150
160
  throw new BaseError(
151
161
  ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,