react-native-okhi 1.0.30-beta.2 → 1.0.30-beta.3

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.
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.0.30-beta.2"
3
+ "version": "1.0.30-beta.3"
4
4
  }
@@ -45,8 +45,13 @@ const isBackgroundLocationPermissionGrantedAndroid = async () => {
45
45
  return await isLocationPermissionGranted();
46
46
  }
47
47
 
48
- const hasPermission = await _reactNative.PermissionsAndroid.check(_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION);
49
- return hasPermission;
48
+ if (typeof _reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION !== 'undefined') {
49
+ const hasPermission = await _reactNative.PermissionsAndroid.check(_reactNative.PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION);
50
+ return hasPermission;
51
+ }
52
+
53
+ console.warn(`PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION is undefined, this is an issue with the current version of RN you are running. Please consider upgrading`);
54
+ return false;
50
55
  };
51
56
 
52
57
  const isBackgroundLocationPermissionGrantedIOS = () => {
@@ -1 +1 @@
1
- {"version":3,"names":["isLocationServicesEnabled","isValidPlatform","OkHiNativeModule","isLocationPermissionGranted","isBackgroundLocationPermissionGrantedAndroid","sdkVersion","getSystemVersion","hasPermission","PermissionsAndroid","check","PERMISSIONS","ACCESS_BACKGROUND_LOCATION","isBackgroundLocationPermissionGrantedIOS","isBackgroundLocationPermissionGranted","fn","Platform","OS","requestLocationPermissionAndroid","status","requestMultiple","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","requestLocationPermissionIOS","requestLocationPermission","isGranted","errorHandler","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices","request","locationPermissionType","rationale","callback","serviceError","OkHiException","code","SERVICE_UNAVAILABLE_CODE","message","googlePlayError","handleError","error","handleGooglePlayServiceRequest","then","googlePlayStatus","handleRationaleRequest","handleRationaleAlert","alertRationale","Promise","resolve","_","Alert","alert","title","text","grantButton","label","onPress","denyButton","style","onDismiss","handlePermissionRequest","OkHiNativeEvents","removeAllListeners","addListener","permissionUpdate","whenInUseResult","initialWhenInUseResult","alwaysResult","currentStatus","retriveLocationPermissionStatus","showRationale","result","serviceStatus","enableResult","catch","openAppSettings","alwaysPerm","whenInUsePerm","requestTrackingAuthorization","canOpenProtectedAppsSettings","openProtectedAppsSettings"],"sources":["Helpers.ts"],"sourcesContent":["import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';\nimport { Alert, Permission, PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\nimport type {\n LocationPermissionCallback,\n LocationPermissionStatus,\n LocationRequestPermissionType,\n} from './types';\nimport { OkHiException } from './OkHiException';\n\n/**\n * Checks whether location services are enabled\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available\n */\nexport const isLocationServicesEnabled = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationServicesEnabled);\n};\n\n/**\n * Checks whether when in use location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isLocationPermissionGranted = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationPermissionGranted);\n};\n\nconst isBackgroundLocationPermissionGrantedAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) {\n return true;\n }\n if (sdkVersion < 29) {\n return await isLocationPermissionGranted();\n }\n const hasPermission = await PermissionsAndroid.check(\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION as Permission\n );\n return hasPermission;\n };\n\nconst isBackgroundLocationPermissionGrantedIOS = (): Promise<boolean> => {\n return OkHiNativeModule.isBackgroundLocationPermissionGranted();\n};\n\n/**\n * Checks whether background location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isBackgroundLocationPermissionGranted = (): Promise<boolean> => {\n const fn =\n Platform.OS === 'android'\n ? isBackgroundLocationPermissionGrantedAndroid\n : isBackgroundLocationPermissionGrantedIOS;\n return isValidPlatform(fn);\n};\n\nconst requestLocationPermissionAndroid = async (): Promise<boolean> => {\n const status: any = await PermissionsAndroid.requestMultiple([\n PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION as Permission,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,\n ]);\n return status['android.permission.ACCESS_FINE_LOCATION'] === 'granted';\n};\n\nconst requestLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestLocationPermission();\n};\n\n/**\n * Requests for when in use location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestLocationPermission = async (): Promise<boolean> => {\n const isGranted = await isLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestLocationPermissionAndroid\n : requestLocationPermissionIOS\n );\n};\n\nconst requestBackgroundLocationPermissionAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) return true;\n if (sdkVersion >= 29) {\n const permissions: any = [\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,\n ];\n const status: any = await PermissionsAndroid.requestMultiple(permissions);\n return (\n status['android.permission.ACCESS_BACKGROUND_LOCATION'] === 'granted'\n );\n } else {\n return await requestLocationPermissionAndroid();\n }\n };\n\nconst requestBackgroundLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestBackgroundLocationPermission();\n};\n\n/**\n * Requests for background location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestBackgroundLocationPermission =\n async (): Promise<boolean> => {\n const isGranted = await isBackgroundLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestBackgroundLocationPermissionAndroid\n : requestBackgroundLocationPermissionIOS\n );\n };\n\n/**\n * Requests the user to enable location services by showing an in app modal on android and opening location settings on iOS\n * @returns {Promise<boolean>} A promise that resolves to either a boolean value on android or null on iOS\n */\nexport const requestEnableLocationServices = (): Promise<boolean | null> => {\n return isValidPlatform(OkHiNativeModule.requestEnableLocationServices);\n};\n\n/**\n * Android Only - Checks if Google Play Services is available\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const isGooglePlayServicesAvailable = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.isGooglePlayServicesAvailable,\n 'android'\n );\n};\n\n/**\n * Android Only - Requests user to enable Google Play Services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const requestEnableGooglePlayServices = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.requestEnableGooglePlayServices,\n 'android'\n );\n};\n\n/**\n * Returns the system version of the current platform\n * @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android\n */\nexport const getSystemVersion = (): Promise<string | number> =>\n isValidPlatform(OkHiNativeModule.getSystemVersion);\n\n/**\n * Requests location permission from the user. It'll also attempt to activate any disbaled services (Android Only)\n */\nexport const request = (\n locationPermissionType: LocationRequestPermissionType,\n rationale: {\n title: string;\n text: string;\n successButton?: { label: string };\n denyButton?: { label: string };\n } | null,\n callback: LocationPermissionCallback\n) => {\n const serviceError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Location service is currently not available. Please enable in app settings',\n });\n\n const googlePlayError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Google Play Services is currently unavailable. Please enable in settings',\n });\n\n const handleError = (error: OkHiException) => {\n callback(null, error);\n };\n\n const handleGooglePlayServiceRequest = () => {\n requestEnableGooglePlayServices().then((googlePlayStatus) => {\n if (!googlePlayStatus) {\n handleError(googlePlayError);\n } else {\n handleRationaleRequest();\n }\n });\n };\n\n const handleRationaleAlert = (alertRationale: {\n title: string;\n text: string;\n grantButton?: { label: string };\n denyButton?: { label: string };\n }) => {\n return new Promise((resolve, _) => {\n Alert.alert(\n alertRationale.title,\n alertRationale.text,\n [\n {\n text: alertRationale.grantButton\n ? alertRationale.grantButton.label\n : 'Grant',\n onPress: () => {\n resolve(true);\n },\n },\n {\n text: alertRationale.denyButton\n ? alertRationale.denyButton.label\n : 'Deny',\n onPress: () => {\n resolve(false);\n },\n style: 'cancel',\n },\n ],\n {\n onDismiss: () => {\n resolve(false);\n },\n }\n );\n });\n };\n\n const handlePermissionRequest = () => {\n if (Platform.OS === 'ios') {\n OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');\n OkHiNativeEvents.addListener(\n 'onLocationPermissionStatusUpdate',\n (permissionUpdate) => {\n callback(permissionUpdate, null);\n }\n );\n if (locationPermissionType === 'whenInUse') {\n OkHiNativeModule.requestLocationPermission();\n } else {\n OkHiNativeModule.requestBackgroundLocationPermission();\n }\n } else {\n if (locationPermissionType === 'whenInUse') {\n requestLocationPermissionAndroid().then((whenInUseResult) =>\n callback(whenInUseResult ? 'authorizedWhenInUse' : 'denied', null)\n );\n } else {\n requestLocationPermissionAndroid().then((initialWhenInUseResult) => {\n if (!initialWhenInUseResult) {\n callback('denied', null);\n } else {\n callback('authorizedWhenInUse', null);\n requestBackgroundLocationPermission().then((alwaysResult) => {\n callback(\n alwaysResult ? 'authorizedAlways' : 'authorizedWhenInUse',\n null\n );\n });\n }\n });\n }\n }\n };\n\n const handleRationaleRequest = async () => {\n const currentStatus = await retriveLocationPermissionStatus();\n let showRationale = true;\n if (\n locationPermissionType === 'whenInUse' &&\n (currentStatus === 'authorizedWhenInUse' ||\n currentStatus === 'authorizedAlways')\n ) {\n showRationale = false;\n }\n if (\n locationPermissionType === 'always' &&\n currentStatus === 'authorizedAlways'\n ) {\n showRationale = false;\n }\n if (rationale && showRationale) {\n const result = await handleRationaleAlert(rationale);\n if (!result) {\n callback('rationaleDissmissed', null);\n } else {\n handlePermissionRequest();\n }\n } else {\n handlePermissionRequest();\n }\n };\n\n isLocationServicesEnabled()\n .then((serviceStatus) => {\n if (!serviceStatus && Platform.OS === 'ios') {\n handleError(serviceError);\n } else if (!serviceStatus && Platform.OS === 'android') {\n requestEnableLocationServices()\n .then((enableResult) => {\n if (!enableResult) {\n handleError(serviceError);\n } else {\n handleGooglePlayServiceRequest();\n }\n })\n .catch(handleError);\n } else {\n if (Platform.OS === 'ios') {\n handleRationaleRequest();\n } else {\n handleGooglePlayServiceRequest();\n }\n }\n })\n .catch(handleError);\n};\n\n/**\n * Open the device's app settings.\n */\nexport const openAppSettings = () => {\n OkHiNativeModule.openAppSettings();\n};\n\n/**\n * Retrives the location permission status from the device\n */\nexport const retriveLocationPermissionStatus =\n async (): Promise<LocationPermissionStatus> => {\n if (Platform.OS === 'ios') {\n return OkHiNativeModule.retriveLocationPermissionStatus() as Promise<LocationPermissionStatus>;\n }\n const alwaysPerm = await isBackgroundLocationPermissionGranted();\n if (alwaysPerm) {\n return 'authorizedAlways';\n }\n const whenInUsePerm = await isLocationPermissionGranted();\n return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';\n };\n\n/**\n * Requests tracking authorization from the user. iOS only, iOS version >= 14\n * Read more: https://developer.apple.com/app-store/user-privacy-and-data-use/\n */\nexport const requestTrackingAuthorization = async (): Promise<\n string | null\n> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.requestTrackingAuthorization();\n return result;\n }, 'ios');\n};\n\n/**\n * Checks whether current device can open \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const canOpenProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.canOpenProtectedAppsSettings();\n return result;\n }, 'android');\n};\n\n/**\n * Opens \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const openProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.openProtectedAppsSettings();\n return result;\n }, 'android');\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAMA;;AAEA;AACA;AACA;AACA;AACO,MAAMA,yBAAyB,GAAG,MAAwB;EAC/D,OAAO,IAAAC,wBAAA,EAAgBC,kCAAA,CAAiBF,yBAAjC,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;;;;;AACO,MAAMG,2BAA2B,GAAG,MAAwB;EACjE,OAAO,IAAAF,wBAAA,EAAgBC,kCAAA,CAAiBC,2BAAjC,CAAP;AACD,CAFM;;;;AAIP,MAAMC,4CAA4C,GAChD,YAA8B;EAC5B,MAAMC,UAAU,GAAG,MAAMH,kCAAA,CAAiBI,gBAAjB,EAAzB;;EACA,IAAID,UAAU,GAAG,EAAjB,EAAqB;IACnB,OAAO,IAAP;EACD;;EACD,IAAIA,UAAU,GAAG,EAAjB,EAAqB;IACnB,OAAO,MAAMF,2BAA2B,EAAxC;EACD;;EACD,MAAMI,aAAa,GAAG,MAAMC,+BAAA,CAAmBC,KAAnB,CAC1BD,+BAAA,CAAmBE,WAAnB,CAA+BC,0BADL,CAA5B;EAGA,OAAOJ,aAAP;AACD,CAbH;;AAeA,MAAMK,wCAAwC,GAAG,MAAwB;EACvE,OAAOV,kCAAA,CAAiBW,qCAAjB,EAAP;AACD,CAFD;AAIA;AACA;AACA;AACA;;;AACO,MAAMA,qCAAqC,GAAG,MAAwB;EAC3E,MAAMC,EAAE,GACNC,qBAAA,CAASC,EAAT,KAAgB,SAAhB,GACIZ,4CADJ,G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IACjC,MAAM0E,MAAM,GAAG,MAAMzE,kCAAA,CAAiBgF,4BAAjB,EAArB;IACA,OAAOP,MAAP;EACD,CAHM,EAGJ,KAHI,CAAP;AAID,CAPM;AASP;AACA;AACA;AACA;;;;;AACO,MAAMQ,4BAA4B,GAAG,MAAwB;EAClE,OAAO,IAAAlF,wBAAA,EAAgB,YAAY;IACjC,MAAM0E,MAAM,GAAG,MAAMzE,kCAAA,CAAiBiF,4BAAjB,EAArB;IACA,OAAOR,MAAP;EACD,CAHM,EAGJ,SAHI,CAAP;AAID,CALM;AAOP;AACA;AACA;AACA;;;;;AACO,MAAMS,yBAAyB,GAAG,MAAwB;EAC/D,OAAO,IAAAnF,wBAAA,EAAgB,YAAY;IACjC,MAAM0E,MAAM,GAAG,MAAMzE,kCAAA,CAAiBkF,yBAAjB,EAArB;IACA,OAAOT,MAAP;EACD,CAHM,EAGJ,SAHI,CAAP;AAID,CALM"}
1
+ {"version":3,"names":["isLocationServicesEnabled","isValidPlatform","OkHiNativeModule","isLocationPermissionGranted","isBackgroundLocationPermissionGrantedAndroid","sdkVersion","getSystemVersion","PermissionsAndroid","PERMISSIONS","ACCESS_BACKGROUND_LOCATION","hasPermission","check","console","warn","isBackgroundLocationPermissionGrantedIOS","isBackgroundLocationPermissionGranted","fn","Platform","OS","requestLocationPermissionAndroid","status","requestMultiple","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","requestLocationPermissionIOS","requestLocationPermission","isGranted","errorHandler","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices","request","locationPermissionType","rationale","callback","serviceError","OkHiException","code","SERVICE_UNAVAILABLE_CODE","message","googlePlayError","handleError","error","handleGooglePlayServiceRequest","then","googlePlayStatus","handleRationaleRequest","handleRationaleAlert","alertRationale","Promise","resolve","_","Alert","alert","title","text","grantButton","label","onPress","denyButton","style","onDismiss","handlePermissionRequest","OkHiNativeEvents","removeAllListeners","addListener","permissionUpdate","whenInUseResult","initialWhenInUseResult","alwaysResult","currentStatus","retriveLocationPermissionStatus","showRationale","result","serviceStatus","enableResult","catch","openAppSettings","alwaysPerm","whenInUsePerm","requestTrackingAuthorization","canOpenProtectedAppsSettings","openProtectedAppsSettings"],"sources":["Helpers.ts"],"sourcesContent":["import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';\nimport { Alert, Permission, PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\nimport type {\n LocationPermissionCallback,\n LocationPermissionStatus,\n LocationRequestPermissionType,\n} from './types';\nimport { OkHiException } from './OkHiException';\n\n/**\n * Checks whether location services are enabled\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available\n */\nexport const isLocationServicesEnabled = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationServicesEnabled);\n};\n\n/**\n * Checks whether when in use location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isLocationPermissionGranted = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationPermissionGranted);\n};\n\nconst isBackgroundLocationPermissionGrantedAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) {\n return true;\n }\n if (sdkVersion < 29) {\n return await isLocationPermissionGranted();\n }\n if (\n typeof PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION !==\n 'undefined'\n ) {\n const hasPermission = await PermissionsAndroid.check(\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION as Permission\n );\n return hasPermission;\n }\n console.warn(\n `PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION is undefined, this is an issue with the current version of RN you are running. Please consider upgrading`\n );\n return false;\n };\n\nconst isBackgroundLocationPermissionGrantedIOS = (): Promise<boolean> => {\n return OkHiNativeModule.isBackgroundLocationPermissionGranted();\n};\n\n/**\n * Checks whether background location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isBackgroundLocationPermissionGranted = (): Promise<boolean> => {\n const fn =\n Platform.OS === 'android'\n ? isBackgroundLocationPermissionGrantedAndroid\n : isBackgroundLocationPermissionGrantedIOS;\n return isValidPlatform(fn);\n};\n\nconst requestLocationPermissionAndroid = async (): Promise<boolean> => {\n const status: any = await PermissionsAndroid.requestMultiple([\n PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION as Permission,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,\n ]);\n return status['android.permission.ACCESS_FINE_LOCATION'] === 'granted';\n};\n\nconst requestLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestLocationPermission();\n};\n\n/**\n * Requests for when in use location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestLocationPermission = async (): Promise<boolean> => {\n const isGranted = await isLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestLocationPermissionAndroid\n : requestLocationPermissionIOS\n );\n};\n\nconst requestBackgroundLocationPermissionAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) return true;\n if (sdkVersion >= 29) {\n const permissions: any = [\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,\n ];\n const status: any = await PermissionsAndroid.requestMultiple(permissions);\n return (\n status['android.permission.ACCESS_BACKGROUND_LOCATION'] === 'granted'\n );\n } else {\n return await requestLocationPermissionAndroid();\n }\n };\n\nconst requestBackgroundLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestBackgroundLocationPermission();\n};\n\n/**\n * Requests for background location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestBackgroundLocationPermission =\n async (): Promise<boolean> => {\n const isGranted = await isBackgroundLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestBackgroundLocationPermissionAndroid\n : requestBackgroundLocationPermissionIOS\n );\n };\n\n/**\n * Requests the user to enable location services by showing an in app modal on android and opening location settings on iOS\n * @returns {Promise<boolean>} A promise that resolves to either a boolean value on android or null on iOS\n */\nexport const requestEnableLocationServices = (): Promise<boolean | null> => {\n return isValidPlatform(OkHiNativeModule.requestEnableLocationServices);\n};\n\n/**\n * Android Only - Checks if Google Play Services is available\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const isGooglePlayServicesAvailable = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.isGooglePlayServicesAvailable,\n 'android'\n );\n};\n\n/**\n * Android Only - Requests user to enable Google Play Services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const requestEnableGooglePlayServices = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.requestEnableGooglePlayServices,\n 'android'\n );\n};\n\n/**\n * Returns the system version of the current platform\n * @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android\n */\nexport const getSystemVersion = (): Promise<string | number> =>\n isValidPlatform(OkHiNativeModule.getSystemVersion);\n\n/**\n * Requests location permission from the user. It'll also attempt to activate any disbaled services (Android Only)\n */\nexport const request = (\n locationPermissionType: LocationRequestPermissionType,\n rationale: {\n title: string;\n text: string;\n successButton?: { label: string };\n denyButton?: { label: string };\n } | null,\n callback: LocationPermissionCallback\n) => {\n const serviceError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Location service is currently not available. Please enable in app settings',\n });\n\n const googlePlayError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Google Play Services is currently unavailable. Please enable in settings',\n });\n\n const handleError = (error: OkHiException) => {\n callback(null, error);\n };\n\n const handleGooglePlayServiceRequest = () => {\n requestEnableGooglePlayServices().then((googlePlayStatus) => {\n if (!googlePlayStatus) {\n handleError(googlePlayError);\n } else {\n handleRationaleRequest();\n }\n });\n };\n\n const handleRationaleAlert = (alertRationale: {\n title: string;\n text: string;\n grantButton?: { label: string };\n denyButton?: { label: string };\n }) => {\n return new Promise((resolve, _) => {\n Alert.alert(\n alertRationale.title,\n alertRationale.text,\n [\n {\n text: alertRationale.grantButton\n ? alertRationale.grantButton.label\n : 'Grant',\n onPress: () => {\n resolve(true);\n },\n },\n {\n text: alertRationale.denyButton\n ? alertRationale.denyButton.label\n : 'Deny',\n onPress: () => {\n resolve(false);\n },\n style: 'cancel',\n },\n ],\n {\n onDismiss: () => {\n resolve(false);\n },\n }\n );\n });\n };\n\n const handlePermissionRequest = () => {\n if (Platform.OS === 'ios') {\n OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');\n OkHiNativeEvents.addListener(\n 'onLocationPermissionStatusUpdate',\n (permissionUpdate) => {\n callback(permissionUpdate, null);\n }\n );\n if (locationPermissionType === 'whenInUse') {\n OkHiNativeModule.requestLocationPermission();\n } else {\n OkHiNativeModule.requestBackgroundLocationPermission();\n }\n } else {\n if (locationPermissionType === 'whenInUse') {\n requestLocationPermissionAndroid().then((whenInUseResult) =>\n callback(whenInUseResult ? 'authorizedWhenInUse' : 'denied', null)\n );\n } else {\n requestLocationPermissionAndroid().then((initialWhenInUseResult) => {\n if (!initialWhenInUseResult) {\n callback('denied', null);\n } else {\n callback('authorizedWhenInUse', null);\n requestBackgroundLocationPermission().then((alwaysResult) => {\n callback(\n alwaysResult ? 'authorizedAlways' : 'authorizedWhenInUse',\n null\n );\n });\n }\n });\n }\n }\n };\n\n const handleRationaleRequest = async () => {\n const currentStatus = await retriveLocationPermissionStatus();\n let showRationale = true;\n if (\n locationPermissionType === 'whenInUse' &&\n (currentStatus === 'authorizedWhenInUse' ||\n currentStatus === 'authorizedAlways')\n ) {\n showRationale = false;\n }\n if (\n locationPermissionType === 'always' &&\n currentStatus === 'authorizedAlways'\n ) {\n showRationale = false;\n }\n if (rationale && showRationale) {\n const result = await handleRationaleAlert(rationale);\n if (!result) {\n callback('rationaleDissmissed', null);\n } else {\n handlePermissionRequest();\n }\n } else {\n handlePermissionRequest();\n }\n };\n\n isLocationServicesEnabled()\n .then((serviceStatus) => {\n if (!serviceStatus && Platform.OS === 'ios') {\n handleError(serviceError);\n } else if (!serviceStatus && Platform.OS === 'android') {\n requestEnableLocationServices()\n .then((enableResult) => {\n if (!enableResult) {\n handleError(serviceError);\n } else {\n handleGooglePlayServiceRequest();\n }\n })\n .catch(handleError);\n } else {\n if (Platform.OS === 'ios') {\n handleRationaleRequest();\n } else {\n handleGooglePlayServiceRequest();\n }\n }\n })\n .catch(handleError);\n};\n\n/**\n * Open the device's app settings.\n */\nexport const openAppSettings = () => {\n OkHiNativeModule.openAppSettings();\n};\n\n/**\n * Retrives the location permission status from the device\n */\nexport const retriveLocationPermissionStatus =\n async (): Promise<LocationPermissionStatus> => {\n if (Platform.OS === 'ios') {\n return OkHiNativeModule.retriveLocationPermissionStatus() as Promise<LocationPermissionStatus>;\n }\n const alwaysPerm = await isBackgroundLocationPermissionGranted();\n if (alwaysPerm) {\n return 'authorizedAlways';\n }\n const whenInUsePerm = await isLocationPermissionGranted();\n return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';\n };\n\n/**\n * Requests tracking authorization from the user. iOS only, iOS version >= 14\n * Read more: https://developer.apple.com/app-store/user-privacy-and-data-use/\n */\nexport const requestTrackingAuthorization = async (): Promise<\n string | null\n> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.requestTrackingAuthorization();\n return result;\n }, 'ios');\n};\n\n/**\n * Checks whether current device can open \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const canOpenProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.canOpenProtectedAppsSettings();\n return result;\n }, 'android');\n};\n\n/**\n * Opens \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const openProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.openProtectedAppsSettings();\n return result;\n }, 'android');\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAMA;;AAEA;AACA;AACA;AACA;AACO,MAAMA,yBAAyB,GAAG,MAAwB;EAC/D,OAAO,IAAAC,wBAAA,EAAgBC,kCAAA,CAAiBF,yBAAjC,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;;;;;AACO,MAAMG,2BAA2B,GAAG,MAAwB;EACjE,OAAO,IAAAF,wBAAA,EAAgBC,kCAAA,CAAiBC,2BAAjC,CAAP;AACD,CAFM;;;;AAIP,MAAMC,4CAA4C,GAChD,YAA8B;EAC5B,MAAMC,UAAU,GAAG,MAAMH,kCAAA,CAAiBI,gBAAjB,EAAzB;;EACA,IAAID,UAAU,GAAG,EAAjB,EAAqB;IACnB,OAAO,IAAP;EACD;;EACD,IAAIA,UAAU,GAAG,EAAjB,EAAqB;IACnB,OAAO,MAAMF,2BAA2B,EAAxC;EACD;;EACD,IACE,OAAOI,+BAAA,CAAmBC,WAAnB,CAA+BC,0BAAtC,KACA,WAFF,EAGE;IACA,MAAMC,aAAa,GAAG,MAAMH,+BAAA,CAAmBI,KAAnB,CAC1BJ,+BAAA,CAAmBC,WAAnB,CAA+BC,0BADL,CAA5B;IAGA,OAAOC,aAAP;EACD;;EACDE,OAAO,CAACC,IAAR,CACG,oKADH;EAGA,OAAO,KAAP;AACD,CAtBH;;AAwBA,MAAMC,wCAAwC,GAAG,MAAwB;EACvE,OAAOZ,kCAAA,CAAiBa,qCAAjB,EAAP;AACD,CAFD;AAIA;AACA;AACA;AACA;;;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D,CAXI;AAaP;AACA;AACA;AACA;;;;;AACO,MAAMC,4BAA4B,GAAG,YAEvC;EACH,OAAO,IAAAnF,wBAAA,EAAgB,YAAY;IACjC,MAAM4E,MAAM,GAAG,MAAM3E,kCAAA,CAAiBkF,4BAAjB,EAArB;IACA,OAAOP,MAAP;EACD,CAHM,EAGJ,KAHI,CAAP;AAID,CAPM;AASP;AACA;AACA;AACA;;;;;AACO,MAAMQ,4BAA4B,GAAG,MAAwB;EAClE,OAAO,IAAApF,wBAAA,EAAgB,YAAY;IACjC,MAAM4E,MAAM,GAAG,MAAM3E,kCAAA,CAAiBmF,4BAAjB,EAArB;IACA,OAAOR,MAAP;EACD,CAHM,EAGJ,SAHI,CAAP;AAID,CALM;AAOP;AACA;AACA;AACA;;;;;AACO,MAAMS,yBAAyB,GAAG,MAAwB;EAC/D,OAAO,IAAArF,wBAAA,EAAgB,YAAY;IACjC,MAAM4E,MAAM,GAAG,MAAM3E,kCAAA,CAAiBoF,yBAAjB,EAArB;IACA,OAAOT,MAAP;EACD,CAHM,EAGJ,SAHI,CAAP;AAID,CALM"}
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.0.30-beta.2"
3
+ "version": "1.0.30-beta.3"
4
4
  }
@@ -30,8 +30,13 @@ const isBackgroundLocationPermissionGrantedAndroid = async () => {
30
30
  return await isLocationPermissionGranted();
31
31
  }
32
32
 
33
- const hasPermission = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION);
34
- return hasPermission;
33
+ if (typeof PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION !== 'undefined') {
34
+ const hasPermission = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION);
35
+ return hasPermission;
36
+ }
37
+
38
+ console.warn(`PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION is undefined, this is an issue with the current version of RN you are running. Please consider upgrading`);
39
+ return false;
35
40
  };
36
41
 
37
42
  const isBackgroundLocationPermissionGrantedIOS = () => {
@@ -1 +1 @@
1
- {"version":3,"names":["OkHiNativeModule","OkHiNativeEvents","Alert","PermissionsAndroid","Platform","errorHandler","isValidPlatform","OkHiException","isLocationServicesEnabled","isLocationPermissionGranted","isBackgroundLocationPermissionGrantedAndroid","sdkVersion","getSystemVersion","hasPermission","check","PERMISSIONS","ACCESS_BACKGROUND_LOCATION","isBackgroundLocationPermissionGrantedIOS","isBackgroundLocationPermissionGranted","fn","OS","requestLocationPermissionAndroid","status","requestMultiple","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","requestLocationPermissionIOS","requestLocationPermission","isGranted","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices","request","locationPermissionType","rationale","callback","serviceError","code","SERVICE_UNAVAILABLE_CODE","message","googlePlayError","handleError","error","handleGooglePlayServiceRequest","then","googlePlayStatus","handleRationaleRequest","handleRationaleAlert","alertRationale","Promise","resolve","_","alert","title","text","grantButton","label","onPress","denyButton","style","onDismiss","handlePermissionRequest","removeAllListeners","addListener","permissionUpdate","whenInUseResult","initialWhenInUseResult","alwaysResult","currentStatus","retriveLocationPermissionStatus","showRationale","result","serviceStatus","enableResult","catch","openAppSettings","alwaysPerm","whenInUsePerm","requestTrackingAuthorization","canOpenProtectedAppsSettings","openProtectedAppsSettings"],"sources":["Helpers.ts"],"sourcesContent":["import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';\nimport { Alert, Permission, PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\nimport type {\n LocationPermissionCallback,\n LocationPermissionStatus,\n LocationRequestPermissionType,\n} from './types';\nimport { OkHiException } from './OkHiException';\n\n/**\n * Checks whether location services are enabled\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available\n */\nexport const isLocationServicesEnabled = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationServicesEnabled);\n};\n\n/**\n * Checks whether when in use location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isLocationPermissionGranted = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationPermissionGranted);\n};\n\nconst isBackgroundLocationPermissionGrantedAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) {\n return true;\n }\n if (sdkVersion < 29) {\n return await isLocationPermissionGranted();\n }\n const hasPermission = await PermissionsAndroid.check(\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION as Permission\n );\n return hasPermission;\n };\n\nconst isBackgroundLocationPermissionGrantedIOS = (): Promise<boolean> => {\n return OkHiNativeModule.isBackgroundLocationPermissionGranted();\n};\n\n/**\n * Checks whether background location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isBackgroundLocationPermissionGranted = (): Promise<boolean> => {\n const fn =\n Platform.OS === 'android'\n ? isBackgroundLocationPermissionGrantedAndroid\n : isBackgroundLocationPermissionGrantedIOS;\n return isValidPlatform(fn);\n};\n\nconst requestLocationPermissionAndroid = async (): Promise<boolean> => {\n const status: any = await PermissionsAndroid.requestMultiple([\n PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION as Permission,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,\n ]);\n return status['android.permission.ACCESS_FINE_LOCATION'] === 'granted';\n};\n\nconst requestLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestLocationPermission();\n};\n\n/**\n * Requests for when in use location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestLocationPermission = async (): Promise<boolean> => {\n const isGranted = await isLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestLocationPermissionAndroid\n : requestLocationPermissionIOS\n );\n};\n\nconst requestBackgroundLocationPermissionAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) return true;\n if (sdkVersion >= 29) {\n const permissions: any = [\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,\n ];\n const status: any = await PermissionsAndroid.requestMultiple(permissions);\n return (\n status['android.permission.ACCESS_BACKGROUND_LOCATION'] === 'granted'\n );\n } else {\n return await requestLocationPermissionAndroid();\n }\n };\n\nconst requestBackgroundLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestBackgroundLocationPermission();\n};\n\n/**\n * Requests for background location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestBackgroundLocationPermission =\n async (): Promise<boolean> => {\n const isGranted = await isBackgroundLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestBackgroundLocationPermissionAndroid\n : requestBackgroundLocationPermissionIOS\n );\n };\n\n/**\n * Requests the user to enable location services by showing an in app modal on android and opening location settings on iOS\n * @returns {Promise<boolean>} A promise that resolves to either a boolean value on android or null on iOS\n */\nexport const requestEnableLocationServices = (): Promise<boolean | null> => {\n return isValidPlatform(OkHiNativeModule.requestEnableLocationServices);\n};\n\n/**\n * Android Only - Checks if Google Play Services is available\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const isGooglePlayServicesAvailable = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.isGooglePlayServicesAvailable,\n 'android'\n );\n};\n\n/**\n * Android Only - Requests user to enable Google Play Services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const requestEnableGooglePlayServices = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.requestEnableGooglePlayServices,\n 'android'\n );\n};\n\n/**\n * Returns the system version of the current platform\n * @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android\n */\nexport const getSystemVersion = (): Promise<string | number> =>\n isValidPlatform(OkHiNativeModule.getSystemVersion);\n\n/**\n * Requests location permission from the user. It'll also attempt to activate any disbaled services (Android Only)\n */\nexport const request = (\n locationPermissionType: LocationRequestPermissionType,\n rationale: {\n title: string;\n text: string;\n successButton?: { label: string };\n denyButton?: { label: string };\n } | null,\n callback: LocationPermissionCallback\n) => {\n const serviceError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Location service is currently not available. Please enable in app settings',\n });\n\n const googlePlayError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Google Play Services is currently unavailable. Please enable in settings',\n });\n\n const handleError = (error: OkHiException) => {\n callback(null, error);\n };\n\n const handleGooglePlayServiceRequest = () => {\n requestEnableGooglePlayServices().then((googlePlayStatus) => {\n if (!googlePlayStatus) {\n handleError(googlePlayError);\n } else {\n handleRationaleRequest();\n }\n });\n };\n\n const handleRationaleAlert = (alertRationale: {\n title: string;\n text: string;\n grantButton?: { label: string };\n denyButton?: { label: string };\n }) => {\n return new Promise((resolve, _) => {\n Alert.alert(\n alertRationale.title,\n alertRationale.text,\n [\n {\n text: alertRationale.grantButton\n ? alertRationale.grantButton.label\n : 'Grant',\n onPress: () => {\n resolve(true);\n },\n },\n {\n text: alertRationale.denyButton\n ? alertRationale.denyButton.label\n : 'Deny',\n onPress: () => {\n resolve(false);\n },\n style: 'cancel',\n },\n ],\n {\n onDismiss: () => {\n resolve(false);\n },\n }\n );\n });\n };\n\n const handlePermissionRequest = () => {\n if (Platform.OS === 'ios') {\n OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');\n OkHiNativeEvents.addListener(\n 'onLocationPermissionStatusUpdate',\n (permissionUpdate) => {\n callback(permissionUpdate, null);\n }\n );\n if (locationPermissionType === 'whenInUse') {\n OkHiNativeModule.requestLocationPermission();\n } else {\n OkHiNativeModule.requestBackgroundLocationPermission();\n }\n } else {\n if (locationPermissionType === 'whenInUse') {\n requestLocationPermissionAndroid().then((whenInUseResult) =>\n callback(whenInUseResult ? 'authorizedWhenInUse' : 'denied', null)\n );\n } else {\n requestLocationPermissionAndroid().then((initialWhenInUseResult) => {\n if (!initialWhenInUseResult) {\n callback('denied', null);\n } else {\n callback('authorizedWhenInUse', null);\n requestBackgroundLocationPermission().then((alwaysResult) => {\n callback(\n alwaysResult ? 'authorizedAlways' : 'authorizedWhenInUse',\n null\n );\n });\n }\n });\n }\n }\n };\n\n const handleRationaleRequest = async () => {\n const currentStatus = await retriveLocationPermissionStatus();\n let showRationale = true;\n if (\n locationPermissionType === 'whenInUse' &&\n (currentStatus === 'authorizedWhenInUse' ||\n currentStatus === 'authorizedAlways')\n ) {\n showRationale = false;\n }\n if (\n locationPermissionType === 'always' &&\n currentStatus === 'authorizedAlways'\n ) {\n showRationale = false;\n }\n if (rationale && showRationale) {\n const result = await handleRationaleAlert(rationale);\n if (!result) {\n callback('rationaleDissmissed', null);\n } else {\n handlePermissionRequest();\n }\n } else {\n handlePermissionRequest();\n }\n };\n\n isLocationServicesEnabled()\n .then((serviceStatus) => {\n if (!serviceStatus && Platform.OS === 'ios') {\n handleError(serviceError);\n } else if (!serviceStatus && Platform.OS === 'android') {\n requestEnableLocationServices()\n .then((enableResult) => {\n if (!enableResult) {\n handleError(serviceError);\n } else {\n handleGooglePlayServiceRequest();\n }\n })\n .catch(handleError);\n } else {\n if (Platform.OS === 'ios') {\n handleRationaleRequest();\n } else {\n handleGooglePlayServiceRequest();\n }\n }\n })\n .catch(handleError);\n};\n\n/**\n * Open the device's app settings.\n */\nexport const openAppSettings = () => {\n OkHiNativeModule.openAppSettings();\n};\n\n/**\n * Retrives the location permission status from the device\n */\nexport const retriveLocationPermissionStatus =\n async (): Promise<LocationPermissionStatus> => {\n if (Platform.OS === 'ios') {\n return OkHiNativeModule.retriveLocationPermissionStatus() as Promise<LocationPermissionStatus>;\n }\n const alwaysPerm = await isBackgroundLocationPermissionGranted();\n if (alwaysPerm) {\n return 'authorizedAlways';\n }\n const whenInUsePerm = await isLocationPermissionGranted();\n return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';\n };\n\n/**\n * Requests tracking authorization from the user. iOS only, iOS version >= 14\n * Read more: https://developer.apple.com/app-store/user-privacy-and-data-use/\n */\nexport const requestTrackingAuthorization = async (): Promise<\n string | null\n> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.requestTrackingAuthorization();\n return result;\n }, 'ios');\n};\n\n/**\n * Checks whether current device can open \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const canOpenProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.canOpenProtectedAppsSettings();\n return result;\n }, 'android');\n};\n\n/**\n * Opens \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const openProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.openProtectedAppsSettings();\n return result;\n }, 'android');\n};\n"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,gBAA3B,QAAmD,qBAAnD;AACA,SAASC,KAAT,EAA4BC,kBAA5B,EAAgDC,QAAhD,QAAgE,cAAhE;AACA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,YAA9C;AAMA,SAASC,aAAT,QAA8B,iBAA9B;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,yBAAyB,GAAG,MAAwB;EAC/D,OAAOF,eAAe,CAACN,gBAAgB,CAACQ,yBAAlB,CAAtB;AACD,CAFM;AAIP;AACA;AACA;AACA;;AACA,OAAO,MAAMC,2BAA2B,GAAG,MA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,"names":["OkHiNativeModule","OkHiNativeEvents","Alert","PermissionsAndroid","Platform","errorHandler","isValidPlatform","OkHiException","isLocationServicesEnabled","isLocationPermissionGranted","isBackgroundLocationPermissionGrantedAndroid","sdkVersion","getSystemVersion","PERMISSIONS","ACCESS_BACKGROUND_LOCATION","hasPermission","check","console","warn","isBackgroundLocationPermissionGrantedIOS","isBackgroundLocationPermissionGranted","fn","OS","requestLocationPermissionAndroid","status","requestMultiple","ACCESS_FINE_LOCATION","ACCESS_COARSE_LOCATION","requestLocationPermissionIOS","requestLocationPermission","isGranted","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices","request","locationPermissionType","rationale","callback","serviceError","code","SERVICE_UNAVAILABLE_CODE","message","googlePlayError","handleError","error","handleGooglePlayServiceRequest","then","googlePlayStatus","handleRationaleRequest","handleRationaleAlert","alertRationale","Promise","resolve","_","alert","title","text","grantButton","label","onPress","denyButton","style","onDismiss","handlePermissionRequest","removeAllListeners","addListener","permissionUpdate","whenInUseResult","initialWhenInUseResult","alwaysResult","currentStatus","retriveLocationPermissionStatus","showRationale","result","serviceStatus","enableResult","catch","openAppSettings","alwaysPerm","whenInUsePerm","requestTrackingAuthorization","canOpenProtectedAppsSettings","openProtectedAppsSettings"],"sources":["Helpers.ts"],"sourcesContent":["import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';\nimport { Alert, Permission, PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\nimport type {\n LocationPermissionCallback,\n LocationPermissionStatus,\n LocationRequestPermissionType,\n} from './types';\nimport { OkHiException } from './OkHiException';\n\n/**\n * Checks whether location services are enabled\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the service is available\n */\nexport const isLocationServicesEnabled = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationServicesEnabled);\n};\n\n/**\n * Checks whether when in use location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isLocationPermissionGranted = (): Promise<boolean> => {\n return isValidPlatform(OkHiNativeModule.isLocationPermissionGranted);\n};\n\nconst isBackgroundLocationPermissionGrantedAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) {\n return true;\n }\n if (sdkVersion < 29) {\n return await isLocationPermissionGranted();\n }\n if (\n typeof PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION !==\n 'undefined'\n ) {\n const hasPermission = await PermissionsAndroid.check(\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION as Permission\n );\n return hasPermission;\n }\n console.warn(\n `PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION is undefined, this is an issue with the current version of RN you are running. Please consider upgrading`\n );\n return false;\n };\n\nconst isBackgroundLocationPermissionGrantedIOS = (): Promise<boolean> => {\n return OkHiNativeModule.isBackgroundLocationPermissionGranted();\n};\n\n/**\n * Checks whether background location permission is granted\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const isBackgroundLocationPermissionGranted = (): Promise<boolean> => {\n const fn =\n Platform.OS === 'android'\n ? isBackgroundLocationPermissionGrantedAndroid\n : isBackgroundLocationPermissionGrantedIOS;\n return isValidPlatform(fn);\n};\n\nconst requestLocationPermissionAndroid = async (): Promise<boolean> => {\n const status: any = await PermissionsAndroid.requestMultiple([\n PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION as Permission,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION as Permission,\n ]);\n return status['android.permission.ACCESS_FINE_LOCATION'] === 'granted';\n};\n\nconst requestLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestLocationPermission();\n};\n\n/**\n * Requests for when in use location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestLocationPermission = async (): Promise<boolean> => {\n const isGranted = await isLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestLocationPermissionAndroid\n : requestLocationPermissionIOS\n );\n};\n\nconst requestBackgroundLocationPermissionAndroid =\n async (): Promise<boolean> => {\n const sdkVersion = await OkHiNativeModule.getSystemVersion();\n if (sdkVersion < 23) return true;\n if (sdkVersion >= 29) {\n const permissions: any = [\n PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION,\n ];\n const status: any = await PermissionsAndroid.requestMultiple(permissions);\n return (\n status['android.permission.ACCESS_BACKGROUND_LOCATION'] === 'granted'\n );\n } else {\n return await requestLocationPermissionAndroid();\n }\n };\n\nconst requestBackgroundLocationPermissionIOS = (): Promise<boolean> => {\n return OkHiNativeModule.requestBackgroundLocationPermission();\n};\n\n/**\n * Requests for background location permission\n * @returns {Promise<boolean>} A promise that resolves to a boolen value indicating whether the permission is granted\n */\nexport const requestBackgroundLocationPermission =\n async (): Promise<boolean> => {\n const isGranted = await isBackgroundLocationPermissionGranted();\n if (isGranted) return isGranted;\n return errorHandler(\n Platform.OS === 'android'\n ? requestBackgroundLocationPermissionAndroid\n : requestBackgroundLocationPermissionIOS\n );\n };\n\n/**\n * Requests the user to enable location services by showing an in app modal on android and opening location settings on iOS\n * @returns {Promise<boolean>} A promise that resolves to either a boolean value on android or null on iOS\n */\nexport const requestEnableLocationServices = (): Promise<boolean | null> => {\n return isValidPlatform(OkHiNativeModule.requestEnableLocationServices);\n};\n\n/**\n * Android Only - Checks if Google Play Services is available\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const isGooglePlayServicesAvailable = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.isGooglePlayServicesAvailable,\n 'android'\n );\n};\n\n/**\n * Android Only - Requests user to enable Google Play Services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is avaialbe\n */\nexport const requestEnableGooglePlayServices = (): Promise<boolean> => {\n return isValidPlatform(\n OkHiNativeModule.requestEnableGooglePlayServices,\n 'android'\n );\n};\n\n/**\n * Returns the system version of the current platform\n * @returns {Promise<boolean>} A promise that resolves either a string on iOS or number on Android\n */\nexport const getSystemVersion = (): Promise<string | number> =>\n isValidPlatform(OkHiNativeModule.getSystemVersion);\n\n/**\n * Requests location permission from the user. It'll also attempt to activate any disbaled services (Android Only)\n */\nexport const request = (\n locationPermissionType: LocationRequestPermissionType,\n rationale: {\n title: string;\n text: string;\n successButton?: { label: string };\n denyButton?: { label: string };\n } | null,\n callback: LocationPermissionCallback\n) => {\n const serviceError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Location service is currently not available. Please enable in app settings',\n });\n\n const googlePlayError = new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message:\n 'Google Play Services is currently unavailable. Please enable in settings',\n });\n\n const handleError = (error: OkHiException) => {\n callback(null, error);\n };\n\n const handleGooglePlayServiceRequest = () => {\n requestEnableGooglePlayServices().then((googlePlayStatus) => {\n if (!googlePlayStatus) {\n handleError(googlePlayError);\n } else {\n handleRationaleRequest();\n }\n });\n };\n\n const handleRationaleAlert = (alertRationale: {\n title: string;\n text: string;\n grantButton?: { label: string };\n denyButton?: { label: string };\n }) => {\n return new Promise((resolve, _) => {\n Alert.alert(\n alertRationale.title,\n alertRationale.text,\n [\n {\n text: alertRationale.grantButton\n ? alertRationale.grantButton.label\n : 'Grant',\n onPress: () => {\n resolve(true);\n },\n },\n {\n text: alertRationale.denyButton\n ? alertRationale.denyButton.label\n : 'Deny',\n onPress: () => {\n resolve(false);\n },\n style: 'cancel',\n },\n ],\n {\n onDismiss: () => {\n resolve(false);\n },\n }\n );\n });\n };\n\n const handlePermissionRequest = () => {\n if (Platform.OS === 'ios') {\n OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');\n OkHiNativeEvents.addListener(\n 'onLocationPermissionStatusUpdate',\n (permissionUpdate) => {\n callback(permissionUpdate, null);\n }\n );\n if (locationPermissionType === 'whenInUse') {\n OkHiNativeModule.requestLocationPermission();\n } else {\n OkHiNativeModule.requestBackgroundLocationPermission();\n }\n } else {\n if (locationPermissionType === 'whenInUse') {\n requestLocationPermissionAndroid().then((whenInUseResult) =>\n callback(whenInUseResult ? 'authorizedWhenInUse' : 'denied', null)\n );\n } else {\n requestLocationPermissionAndroid().then((initialWhenInUseResult) => {\n if (!initialWhenInUseResult) {\n callback('denied', null);\n } else {\n callback('authorizedWhenInUse', null);\n requestBackgroundLocationPermission().then((alwaysResult) => {\n callback(\n alwaysResult ? 'authorizedAlways' : 'authorizedWhenInUse',\n null\n );\n });\n }\n });\n }\n }\n };\n\n const handleRationaleRequest = async () => {\n const currentStatus = await retriveLocationPermissionStatus();\n let showRationale = true;\n if (\n locationPermissionType === 'whenInUse' &&\n (currentStatus === 'authorizedWhenInUse' ||\n currentStatus === 'authorizedAlways')\n ) {\n showRationale = false;\n }\n if (\n locationPermissionType === 'always' &&\n currentStatus === 'authorizedAlways'\n ) {\n showRationale = false;\n }\n if (rationale && showRationale) {\n const result = await handleRationaleAlert(rationale);\n if (!result) {\n callback('rationaleDissmissed', null);\n } else {\n handlePermissionRequest();\n }\n } else {\n handlePermissionRequest();\n }\n };\n\n isLocationServicesEnabled()\n .then((serviceStatus) => {\n if (!serviceStatus && Platform.OS === 'ios') {\n handleError(serviceError);\n } else if (!serviceStatus && Platform.OS === 'android') {\n requestEnableLocationServices()\n .then((enableResult) => {\n if (!enableResult) {\n handleError(serviceError);\n } else {\n handleGooglePlayServiceRequest();\n }\n })\n .catch(handleError);\n } else {\n if (Platform.OS === 'ios') {\n handleRationaleRequest();\n } else {\n handleGooglePlayServiceRequest();\n }\n }\n })\n .catch(handleError);\n};\n\n/**\n * Open the device's app settings.\n */\nexport const openAppSettings = () => {\n OkHiNativeModule.openAppSettings();\n};\n\n/**\n * Retrives the location permission status from the device\n */\nexport const retriveLocationPermissionStatus =\n async (): Promise<LocationPermissionStatus> => {\n if (Platform.OS === 'ios') {\n return OkHiNativeModule.retriveLocationPermissionStatus() as Promise<LocationPermissionStatus>;\n }\n const alwaysPerm = await isBackgroundLocationPermissionGranted();\n if (alwaysPerm) {\n return 'authorizedAlways';\n }\n const whenInUsePerm = await isLocationPermissionGranted();\n return whenInUsePerm ? 'authorizedWhenInUse' : 'denied';\n };\n\n/**\n * Requests tracking authorization from the user. iOS only, iOS version >= 14\n * Read more: https://developer.apple.com/app-store/user-privacy-and-data-use/\n */\nexport const requestTrackingAuthorization = async (): Promise<\n string | null\n> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.requestTrackingAuthorization();\n return result;\n }, 'ios');\n};\n\n/**\n * Checks whether current device can open \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const canOpenProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.canOpenProtectedAppsSettings();\n return result;\n }, 'android');\n};\n\n/**\n * Opens \"Protected Apps Settings\" available in Transsion Group android devices such as Infinix and Tecno\n * When your application is included in protected apps, verification processes are less likely to be terminated by the OS. Increasing rate of users being verified.\n */\nexport const openProtectedAppsSettings = (): Promise<boolean> => {\n return isValidPlatform(async () => {\n const result = await OkHiNativeModule.openProtectedAppsSettings();\n return result;\n }, 'android');\n};\n"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,gBAA3B,QAAmD,qBAAnD;AACA,SAASC,KAAT,EAA4BC,kBAA5B,EAAgDC,QAAhD,QAAgE,cAAhE;AACA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,YAA9C;AAMA,SAASC,aAAT,QAA8B,iBAA9B;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,yBAAyB,GAAG,MAAwB;EAC/D,OAAOF,eAAe,CAACN,gBA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M;AAOP;AACA;AACA;AACA;;AACA,OAAO,MAAMS,yBAAyB,GAAG,MAAwB;EAC/D,OAAOhF,eAAe,CAAC,YAAY;IACjC,MAAMuE,MAAM,GAAG,MAAM7E,gBAAgB,CAACsF,yBAAjB,EAArB;IACA,OAAOT,MAAP;EACD,CAHqB,EAGnB,SAHmB,CAAtB;AAID,CALM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-okhi",
3
- "version": "1.0.30-beta.2",
3
+ "version": "1.0.30-beta.3",
4
4
  "description": "The OkHi React Native library enables you to collect and verify addresses from your users",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.0.30-beta.2"
3
+ "version": "1.0.30-beta.3"
4
4
  }
@@ -33,10 +33,19 @@ const isBackgroundLocationPermissionGrantedAndroid =
33
33
  if (sdkVersion < 29) {
34
34
  return await isLocationPermissionGranted();
35
35
  }
36
- const hasPermission = await PermissionsAndroid.check(
37
- PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION as Permission
36
+ if (
37
+ typeof PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION !==
38
+ 'undefined'
39
+ ) {
40
+ const hasPermission = await PermissionsAndroid.check(
41
+ PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION as Permission
42
+ );
43
+ return hasPermission;
44
+ }
45
+ console.warn(
46
+ `PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION is undefined, this is an issue with the current version of RN you are running. Please consider upgrading`
38
47
  );
39
- return hasPermission;
48
+ return false;
40
49
  };
41
50
 
42
51
  const isBackgroundLocationPermissionGrantedIOS = (): Promise<boolean> => {