react-native-okhi 1.0.5 → 1.0.9

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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # React Native OkHi
1
+ # OkHi React Native
2
2
 
3
3
  The official OkHi React Native library will enable you to start collecting and verifying your user's addresses.
4
4
 
@@ -16,10 +16,7 @@ Use your sandbox keys while you test and develop, and your production mode keys
16
16
  This library targets android devices >= SDK 23. Make sure you're targeting at-least the same by modifying your `android/build.gradle` file
17
17
 
18
18
  ```gradle
19
- ext {
20
- minSdkVersion = 23
21
- ..//
22
- }
19
+ minSdkVersion = 23
23
20
  ```
24
21
 
25
22
  ### Add necessary permissions to your `AndroidManifest.xml`
@@ -39,7 +36,7 @@ ext {
39
36
  </manifest>
40
37
  ```
41
38
 
42
- If you're targeting Android versions >= 8 and you're using the OkVerify library you need to make sure your users select on "Allow always" when granting permissions otherwise the verification process won't work.
39
+ If you're targeting Android versions > 8 and you're using the OkVerify library you need to make sure your users select on "Allow always" when granting permissions otherwise the verification process won't work.
43
40
 
44
41
  ## iOS
45
42
 
@@ -49,6 +46,18 @@ OkHi obtains verification signals in the background, to enable this make sure to
49
46
 
50
47
  ![background modes](https://storage.googleapis.com/okhi-cdn/files/Screenshot%202021-11-02%20at%2008.01.13.png)
51
48
 
49
+ ### Change your deployment target
50
+
51
+ All OkHi React Native libraries target ios devices >= 12. Make sure you're targeting at-least the same by modifying your both your Podfile and deployment target in xcode.
52
+
53
+ ![deployemnttarget](https://storage.googleapis.com/okhi-cdn/files/Screenshot%202021-11-02%20at%2018.09.04.png)
54
+
55
+ Podile located under: `ios/Podfile`
56
+
57
+ ```xml
58
+ platform :ios, '12.0'
59
+ ```
60
+
52
61
  ### Add necessary permissions to your `Info.plist`
53
62
 
54
63
  ```xml
@@ -60,20 +69,25 @@ OkHi obtains verification signals in the background, to enable this make sure to
60
69
 
61
70
  ## Installation
62
71
 
63
- ```bash
64
- $ yarn add react-native-okhi, react-native-webview
72
+ Run the bellow command in the root directory of your React Native project.
73
+
74
+ ```yaml
75
+ yarn add react-native-okhi react-native-webview
76
+ ```
77
+
78
+ Finally install all required pods by running the following command in the ios directory
79
+
80
+ ```
81
+ cd ios/ && pod install && cd ../
65
82
  ```
66
83
 
67
- ## Usage
84
+ # Usage
68
85
 
69
- ### Initialization
86
+ ## Initialization
70
87
 
71
- Add the following initialisation code to your `index.js` file.
88
+ Add the following initialization code to your index.js file. Replace my_branch_id and my_client_key with the keys provided to you after sign up.
72
89
 
73
- ```js
74
- import { AppRegistry } from 'react-native';
75
- import App from './src/App';
76
- import { name as appName } from './app.json';
90
+ ```javascript
77
91
  import * as OkHi from 'react-native-okhi';
78
92
 
79
93
  OkHi.initialize({
@@ -94,43 +108,67 @@ OkHi.initialize({
94
108
  })
95
109
  .then(() => console.log('init done'))
96
110
  .catch(console.log);
97
-
98
- AppRegistry.registerComponent(appName, () => App);
99
111
  ```
100
112
 
101
- ## Create and verify addresses
113
+ ## Address Creation and Verification
102
114
 
103
- ```tsx
104
- import { useState } from 'react';
105
- import { View } from 'react-native';
115
+ ```javascript
116
+ import React, { useState, useEffect } from 'react';
117
+ import { View, Text } from 'react-native';
118
+ import { OkHiLocationManager, canStartVerification } from 'react-native-okhi';
106
119
 
107
120
  const App = () => {
108
- const [launch, setLaunch] = useState(true);
121
+ const [launch, setLaunch] = useState(false);
122
+
123
+ useEffect(() => {
124
+ canStartVerification({ requestServices: true }).then((result) => {
125
+ setLaunch(result);
126
+ }); // checks & requests for required services for verification to run
127
+ });
128
+
109
129
  const user = {
110
130
  phone: '+254712345678', // required
111
131
  firstName: 'Julius',
112
132
  lastName: 'Kiano',
113
133
  };
114
- const handleOnSuccess = (response) => {
134
+
135
+ const handleOnSuccess = async (response) => {
115
136
  console.log(response.user); // user information
116
137
  console.log(response.location); // address information
117
138
  await response.startVerification();
118
139
  };
140
+
119
141
  const handleOnError = (error) => {
120
142
  console.log(error.code); // user information
121
143
  console.log(error.message); // address information
122
144
  setLaunch(false);
123
145
  };
146
+
147
+ if (launch) {
148
+ return (
149
+ <View style={{ flex: 1 }}>
150
+ <OkHiLocationManager
151
+ user={user}
152
+ launch={launch}
153
+ onSuccess={handleOnSuccess}
154
+ onCloseRequest={() => setLaunch(false)} // called when user taps on the top right close button
155
+ onError={handleOnError}
156
+ />
157
+ </View>
158
+ );
159
+ }
160
+
124
161
  return (
125
- <View>
126
- <OkHiLocationManager
127
- user={user}
128
- launch={launch}
129
- onSuccess={handleOnSuccess}
130
- onCloseRequest={() => setLaunch(false)} // called when user taps on the top right close button
131
- onError={handleOnError}
132
- />
162
+ <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
163
+ <Text>Loading..</Text>
133
164
  </View>
134
165
  );
135
166
  };
167
+
168
+ export default App;
136
169
  ```
170
+
171
+ # Documentation
172
+
173
+ - [Guide](https://docs.okhi.co/v/v5.1-beta/okhi-on-your-react-native-app)
174
+ - [Best practices](https://docs.google.com/document/d/1kxolQJ4n6tEgReuqVLYpDVMW--xvqv5UQ7AdvrN0Uw0/edit)
Binary file
@@ -1,2 +1,2 @@
1
- #Mon Nov 01 16:53:23 EAT 2021
1
+ #Sun Nov 21 16:30:21 EAT 2021
2
2
  gradle.version=6.6.1
@@ -58,5 +58,5 @@ dependencies {
58
58
  //noinspection GradleDynamicVersion
59
59
  implementation "com.facebook.react:react-native:+" // From node_modules
60
60
  implementation 'com.github.okhi:android-core:v1.3.4'
61
- implementation 'com.github.okhi:android-okverify:v1.4.3'
61
+ implementation 'com.github.okhi:android-okverify:v1.4.5'
62
62
  }
package/ios/Okhi.swift CHANGED
@@ -49,6 +49,7 @@ class Okhi: NSObject {
49
49
  okhiLocationService.delegate = self
50
50
  self.resolve = resolve
51
51
  locationPermissionRequestType = .whenInUse
52
+ okhiLocationService.requestLocationPermission(withBackgroundLocationPermission: false)
52
53
  }
53
54
 
54
55
  @objc func requestBackgroundLocationPermission(_ resolve:@escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
@@ -151,17 +152,20 @@ extension Okhi: OkHiLocationServiceDelegate {
151
152
  // MARK: - OkVerify Delegate
152
153
  extension Okhi: OkVerifyDelegate {
153
154
  func verify(_ okVerify: OkHiVerify, didEncounterError error: OkHiError) {
154
- guard let reject = reject else { return }
155
- reject(error.code, error.message, nil)
155
+ guard let rej = reject else { return }
156
+ rej(error.code, error.message, nil)
157
+ reject = nil
156
158
  }
157
159
 
158
160
  func verify(_ okVerify: OkHiVerify, didStart locationId: String) {
159
- guard let resolve = resolve else { return }
160
- resolve(locationId)
161
+ guard let res = resolve else { return }
162
+ res(locationId)
163
+ resolve = nil
161
164
  }
162
165
 
163
166
  func verify(_ okVerify: OkHiVerify, didEnd locationId: String) {
164
- guard let resolve = resolve else { return }
165
- resolve(locationId)
167
+ guard let res = resolve else { return }
168
+ res(locationId)
169
+ resolve = nil
166
170
  }
167
171
  }
@@ -26,6 +26,7 @@ const canStartAddressCreation = configuration => {
26
26
 
27
27
  if (!requestServices) {
28
28
  resolve(locationServicesStatus && googlePlayServices && locationPerm);
29
+ return;
29
30
  }
30
31
 
31
32
  if (!locationServicesStatus && _reactNative.Platform.OS === 'ios') {
@@ -34,10 +35,10 @@ const canStartAddressCreation = configuration => {
34
35
  message: 'Location services is unavailable'
35
36
  }));
36
37
  } else {
37
- const locationServicesRequestStatus = await (0, _Helpers.requestEnableLocationServices)();
38
- const googlePlayServicesRequestStatus = _reactNative.Platform.OS === 'android' ? await (0, _Helpers.requestEnableGooglePlayServices)() : true;
38
+ const locationServicesRequestStatus = _reactNative.Platform.OS === 'ios' ? true : await (0, _Helpers.requestEnableLocationServices)();
39
+ const gPlayServices = _reactNative.Platform.OS === 'android' ? await (0, _Helpers.requestEnableGooglePlayServices)() : true;
39
40
  const locationPermStatus = await (0, _Helpers.requestLocationPermission)();
40
- resolve(locationServicesRequestStatus && googlePlayServicesRequestStatus && locationPermStatus);
41
+ resolve(locationServicesRequestStatus && gPlayServices && locationPermStatus);
41
42
  }
42
43
  });
43
44
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["Helpers.ts"],"names":["canStartAddressCreation","configuration","Promise","resolve","reject","requestServices","locationServicesStatus","googlePlayServices","Platform","OS","locationPerm","OkHiException","code","SERVICE_UNAVAILABLE_CODE","message","locationServicesRequestStatus","googlePlayServicesRequestStatus","locationPermStatus"],"mappings":";;;;;;;AAAA;;AACA;;AAQA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,uBAAuB,GAAIC,aAAD,IAEf;AACtB,SAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;AAC5C,UAAMC,eAAe,GAAGJ,aAAa,IAAIA,aAAa,CAACI,eAAvD;AACA,UAAMC,sBAAsB,GAAG,MAAM,yCAArC;AACA,UAAMC,kBAAkB,GACtBC,sBAASC,EAAT,KAAgB,SAAhB,GAA4B,MAAM,6CAAlC,GAAoE,IADtE;AAEA,UAAMC,YAAY,GAAG,MAAM,2CAA3B;;AACA,QAAI,CAACL,eAAL,EAAsB;AACpBF,MAAAA,OAAO,CAACG,sBAAsB,IAAIC,kBAA1B,IAAgDG,YAAjD,CAAP;AACD;;AACD,QAAI,CAACJ,sBAAD,IAA2BE,sBAASC,EAAT,KAAgB,KAA/C,EAAsD;AACpDL,MAAAA,MAAM,CACJ,IAAIO,4BAAJ,CAAkB;AAChBC,QAAAA,IAAI,EAAED,6BAAcE,wBADJ;AAEhBC,QAAAA,OAAO,EAAE;AAFO,OAAlB,CADI,CAAN;AAMD,KAPD,MAOO;AACL,YAAMC,6BAA6B,GAChC,MAAM,6CADT;AAEA,YAAMC,+BAA+B,GACnCR,sBAASC,EAAT,KAAgB,SAAhB,GACI,MAAM,+CADV,GAEI,IAHN;AAIA,YAAMQ,kBAAkB,GAAG,MAAM,yCAAjC;AACAd,MAAAA,OAAO,CACLY,6BAA6B,IAC3BC,+BADF,IAEEC,kBAHG,CAAP;AAKD;AACF,GA9BM,CAAP;AA+BD,CAlCM","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isLocationServicesEnabled,\n isLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n requestEnableLocationServices,\n requestEnableGooglePlayServices,\n requestLocationPermission,\n} from '../OkCore/Helpers';\nimport { OkHiException } from '../OkCore/OkHiException';\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address creation process.\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user.\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user.\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address creation process.\n */\nexport const canStartAddressCreation = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const locationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(locationServicesStatus && googlePlayServices && locationPerm);\n }\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n (await requestEnableLocationServices()) as boolean;\n const googlePlayServicesRequestStatus =\n Platform.OS === 'android'\n ? await requestEnableGooglePlayServices()\n : true;\n const locationPermStatus = await requestLocationPermission();\n resolve(\n locationServicesRequestStatus &&\n googlePlayServicesRequestStatus &&\n locationPermStatus\n );\n }\n });\n};\n"]}
1
+ {"version":3,"sources":["Helpers.ts"],"names":["canStartAddressCreation","configuration","Promise","resolve","reject","requestServices","locationServicesStatus","googlePlayServices","Platform","OS","locationPerm","OkHiException","code","SERVICE_UNAVAILABLE_CODE","message","locationServicesRequestStatus","gPlayServices","locationPermStatus"],"mappings":";;;;;;;AAAA;;AACA;;AAQA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,uBAAuB,GAAIC,aAAD,IAEf;AACtB,SAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;AAC5C,UAAMC,eAAe,GAAGJ,aAAa,IAAIA,aAAa,CAACI,eAAvD;AACA,UAAMC,sBAAsB,GAAG,MAAM,yCAArC;AACA,UAAMC,kBAAkB,GACtBC,sBAASC,EAAT,KAAgB,SAAhB,GAA4B,MAAM,6CAAlC,GAAoE,IADtE;AAEA,UAAMC,YAAY,GAAG,MAAM,2CAA3B;;AACA,QAAI,CAACL,eAAL,EAAsB;AACpBF,MAAAA,OAAO,CAACG,sBAAsB,IAAIC,kBAA1B,IAAgDG,YAAjD,CAAP;AACA;AACD;;AACD,QAAI,CAACJ,sBAAD,IAA2BE,sBAASC,EAAT,KAAgB,KAA/C,EAAsD;AACpDL,MAAAA,MAAM,CACJ,IAAIO,4BAAJ,CAAkB;AAChBC,QAAAA,IAAI,EAAED,6BAAcE,wBADJ;AAEhBC,QAAAA,OAAO,EAAE;AAFO,OAAlB,CADI,CAAN;AAMD,KAPD,MAOO;AACL,YAAMC,6BAA6B,GACjCP,sBAASC,EAAT,KAAgB,KAAhB,GACI,IADJ,GAEM,MAAM,6CAHd;AAIA,YAAMO,aAAa,GACjBR,sBAASC,EAAT,KAAgB,SAAhB,GACI,MAAM,+CADV,GAEI,IAHN;AAIA,YAAMQ,kBAAkB,GAAG,MAAM,yCAAjC;AACAd,MAAAA,OAAO,CACLY,6BAA6B,IAAIC,aAAjC,IAAkDC,kBAD7C,CAAP;AAGD;AACF,GA/BM,CAAP;AAgCD,CAnCM","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isLocationServicesEnabled,\n isLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n requestEnableLocationServices,\n requestEnableGooglePlayServices,\n requestLocationPermission,\n} from '../OkCore/Helpers';\nimport { OkHiException } from '../OkCore/OkHiException';\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address creation process.\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user.\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user.\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address creation process.\n */\nexport const canStartAddressCreation = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const locationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(locationServicesStatus && googlePlayServices && locationPerm);\n return;\n }\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n Platform.OS === 'ios'\n ? true\n : ((await requestEnableLocationServices()) as boolean);\n const gPlayServices =\n Platform.OS === 'android'\n ? await requestEnableGooglePlayServices()\n : true;\n const locationPermStatus = await requestLocationPermission();\n resolve(\n locationServicesRequestStatus && gPlayServices && locationPermStatus\n );\n }\n });\n};\n"]}
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.0.5"
3
+ "version": "9"
4
4
  }
@@ -160,8 +160,11 @@ const canStartVerification = configuration => {
160
160
 
161
161
  if (!requestServices) {
162
162
  resolve(locationServicesStatus && googlePlayServices && backgroundLocationPerm);
163
+ return;
163
164
  }
164
165
 
166
+ console.log('here..', requestServices);
167
+
165
168
  if (!locationServicesStatus && _reactNative.Platform.OS === 'ios') {
166
169
  reject(new _OkHiException.OkHiException({
167
170
  code: _OkHiException.OkHiException.SERVICE_UNAVAILABLE_CODE,
@@ -169,10 +172,16 @@ const canStartVerification = configuration => {
169
172
  }));
170
173
  } else {
171
174
  const locationServicesRequestStatus = _reactNative.Platform.OS === 'ios' ? true : await (0, _Helpers.requestEnableLocationServices)();
172
- const googlePlayServicesRequestStatus = _reactNative.Platform.OS === 'android' ? await (0, _Helpers.requestEnableGooglePlayServices)() : true;
173
- const whenInUseLocationRequestStatus = await (0, _Helpers.requestLocationPermission)();
174
- const backgroundLocationRequestStatus = await (0, _Helpers.requestBackgroundLocationPermission)();
175
- resolve(locationServicesRequestStatus && googlePlayServicesRequestStatus && whenInUseLocationRequestStatus && backgroundLocationRequestStatus);
175
+ const gPlayServices = _reactNative.Platform.OS === 'ios' ? true : await (0, _Helpers.requestEnableGooglePlayServices)();
176
+ let perm = false;
177
+
178
+ if (_reactNative.Platform.OS === 'ios') {
179
+ perm = await (0, _Helpers.requestBackgroundLocationPermission)();
180
+ } else {
181
+ perm = (await (0, _Helpers.requestLocationPermission)()) && (await (0, _Helpers.requestBackgroundLocationPermission)());
182
+ }
183
+
184
+ resolve(locationServicesRequestStatus && gPlayServices && perm);
176
185
  }
177
186
  });
178
187
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["start","phoneNumber","locationId","lat","lon","configuration","Platform","OS","OkHiNativeModule","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","OkHiException","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","googlePlayServices","backgroundLocationPerm","SERVICE_UNAVAILABLE_CODE","locationServicesRequestStatus","googlePlayServicesRequestStatus","whenInUseLocationRequestStatus","backgroundLocationRequestStatus"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AACA;;AASA;;AACA;;AAGA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,KAMhB;AACH,S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BAAJ,CAAkB;AAChBC,QAAAA,IAAI,EAAED,6BAAcc,wBADJ;AAEhBX,QAAAA,OAAO,EAAE;AAFO,OAAlB,CADI,CAAN;AAMD,KAPD,MAOO;AACL,YAAMY,6BAA6B,GACjC7B,sBAASC,EAAT,KAAgB,KAAhB,GACI,IADJ,GAEM,MAAM,6CAHd;AAIA,YAAM6B,+BAA+B,GACnC9B,sBAASC,EAAT,KAAgB,SAAhB,GACI,MAAM,+CADV,GAEI,IAHN;AAIA,YAAM8B,8BAA8B,GAAG,MAAM,yCAA7C;AACA,YAAMC,+BAA+B,GACnC,MAAM,mDADR;AAEAzB,MAAAA,OAAO,CACLsB,6BAA6B,IAC3BC,+BADF,IAEEC,8BAFF,IAGEC,+BAJG,CAAP;AAMD;AACF,GAtCM,CAAP;AAuCD,CA1CM","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n} from '../OkCore/Helpers';\nimport { errorHandler, isValidPlatform } from '../OkCore/_helpers';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkVerifyStartConfiguration } from './types';\nimport type { OkCollectSuccessResponse } from '../OkCollect/types';\nimport { OkHiException } from '../OkCore/OkHiException';\nexport * from './types';\n/**\n * Starts verification for a particular address\n * @param {string} phoneNumber A users phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @param {number} lat The latitude of the created address\n * @param {number} lon The longitude of the created address\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const start = (\n phoneNumber: string,\n locationId: string,\n lat: number,\n lon: number,\n configuration?: OkVerifyStartConfiguration\n) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration\n );\n } else {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon\n );\n }\n });\n};\n\n/**\n * Starts verification for a particular address using the response object returned by OkCollect\n * @param {Object} response Response returned by OkCollect\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const startVerification = async (\n response: OkCollectSuccessResponse,\n configuration?: OkVerifyStartConfiguration\n) => {\n return new Promise((resolve, reject) => {\n const { location, user } = response;\n if (location.id) {\n if (Platform.OS === 'android') {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon,\n configuration\n );\n resolve(result);\n } else {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon\n );\n resolve(result);\n }\n } else {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n }\n });\n};\n\n/**\n * Stops verification for a particular address using a user's phonenumber and OkHi location identifier\n * @param {string} phoneNumber The user's phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const stopVerification = (phoneNumber: string, locationId: string) => {\n return isValidPlatform(() =>\n OkHiNativeModule.stopAddressVerification(phoneNumber, locationId)\n );\n};\n\n/**\n * Android Only - Starts a foreground service that speeds up rate of verification\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const startForegroundService = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.startForegroundService),\n 'android'\n );\n};\n\n/**\n * Android Only - Stops previously started foreground services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has stopped successfully\n */\nexport const stopForegroundService = () => {\n return isValidPlatform(OkHiNativeModule.stopForegroundService, 'android');\n};\n\n/**\n * Android Only - Checks if the foreground service is running\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is running\n */\nexport const isForegroundServiceRunning = () => {\n return isValidPlatform(\n OkHiNativeModule.isForegroundServiceRunning,\n 'android'\n );\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const canStartVerification = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const backgroundLocationPerm =\n await isBackgroundLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n }\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n Platform.OS === 'ios'\n ? true\n : ((await requestEnableLocationServices()) as boolean);\n const googlePlayServicesRequestStatus =\n Platform.OS === 'android'\n ? await requestEnableGooglePlayServices()\n : true;\n const whenInUseLocationRequestStatus = await requestLocationPermission();\n const backgroundLocationRequestStatus =\n await requestBackgroundLocationPermission();\n resolve(\n locationServicesRequestStatus &&\n googlePlayServicesRequestStatus &&\n whenInUseLocationRequestStatus &&\n backgroundLocationRequestStatus\n );\n }\n });\n};\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["start","phoneNumber","locationId","lat","lon","configuration","Platform","OS","OkHiNativeModule","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","OkHiException","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","googlePlayServices","backgroundLocationPerm","console","log","SERVICE_UNAVAILABLE_CODE","locationServicesRequestStatus","gPlayServices","perm"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AACA;;AASA;;AACA;;AAGA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,KAMhB;AACH,SAAO,8BAAgB,MAAM;AAC3B,QAAIC,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7B,aAAOC,mCAAiBC,wBAAjB,CACLR,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aALK,CAAP;AAOD,KARD,MAQO;AACL,aAAOG,mCAAiBC,wBAAjB,CACLR,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,CAAP;AAMD;AACF,GAjBM,CAAP;AAkBD,CAzBM;AA2BP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMM,iBAAiB,GAAG,OAC/BC,QAD+B,EAE/BN,aAF+B,KAG5B;AACH,SAAO,IAAIO,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtC,UAAM;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,QAAqBL,QAA3B;;AACA,QAAII,QAAQ,CAACE,EAAb,EAAiB;AACf,UAAIX,sBAASC,EAAT,KAAgB,SAApB,EAA+B;AAC7B,cAAMW,MAAM,GAAGV,mCAAiBC,wBAAjB,CACbO,IAA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M","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n} from '../OkCore/Helpers';\nimport { errorHandler, isValidPlatform } from '../OkCore/_helpers';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkVerifyStartConfiguration } from './types';\nimport type { OkCollectSuccessResponse } from '../OkCollect/types';\nimport { OkHiException } from '../OkCore/OkHiException';\nexport * from './types';\n/**\n * Starts verification for a particular address\n * @param {string} phoneNumber A users phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @param {number} lat The latitude of the created address\n * @param {number} lon The longitude of the created address\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const start = (\n phoneNumber: string,\n locationId: string,\n lat: number,\n lon: number,\n configuration?: OkVerifyStartConfiguration\n) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration\n );\n } else {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon\n );\n }\n });\n};\n\n/**\n * Starts verification for a particular address using the response object returned by OkCollect\n * @param {Object} response Response returned by OkCollect\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const startVerification = async (\n response: OkCollectSuccessResponse,\n configuration?: OkVerifyStartConfiguration\n) => {\n return new Promise((resolve, reject) => {\n const { location, user } = response;\n if (location.id) {\n if (Platform.OS === 'android') {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon,\n configuration\n );\n resolve(result);\n } else {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon\n );\n resolve(result);\n }\n } else {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n }\n });\n};\n\n/**\n * Stops verification for a particular address using a user's phonenumber and OkHi location identifier\n * @param {string} phoneNumber The user's phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const stopVerification = (phoneNumber: string, locationId: string) => {\n return isValidPlatform(() =>\n OkHiNativeModule.stopAddressVerification(phoneNumber, locationId)\n );\n};\n\n/**\n * Android Only - Starts a foreground service that speeds up rate of verification\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const startForegroundService = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.startForegroundService),\n 'android'\n );\n};\n\n/**\n * Android Only - Stops previously started foreground services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has stopped successfully\n */\nexport const stopForegroundService = () => {\n return isValidPlatform(OkHiNativeModule.stopForegroundService, 'android');\n};\n\n/**\n * Android Only - Checks if the foreground service is running\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is running\n */\nexport const isForegroundServiceRunning = () => {\n return isValidPlatform(\n OkHiNativeModule.isForegroundServiceRunning,\n 'android'\n );\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const canStartVerification = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const backgroundLocationPerm =\n await isBackgroundLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n return;\n }\n console.log('here..', requestServices);\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n Platform.OS === 'ios'\n ? true\n : ((await requestEnableLocationServices()) as boolean);\n const gPlayServices =\n Platform.OS === 'ios' ? true : await requestEnableGooglePlayServices();\n let perm = false;\n if (Platform.OS === 'ios') {\n perm = await requestBackgroundLocationPermission();\n } else {\n perm =\n (await requestLocationPermission()) &&\n (await requestBackgroundLocationPermission());\n }\n resolve(locationServicesRequestStatus && gPlayServices && perm);\n }\n });\n};\n"]}
@@ -17,6 +17,7 @@ export const canStartAddressCreation = configuration => {
17
17
 
18
18
  if (!requestServices) {
19
19
  resolve(locationServicesStatus && googlePlayServices && locationPerm);
20
+ return;
20
21
  }
21
22
 
22
23
  if (!locationServicesStatus && Platform.OS === 'ios') {
@@ -25,10 +26,10 @@ export const canStartAddressCreation = configuration => {
25
26
  message: 'Location services is unavailable'
26
27
  }));
27
28
  } else {
28
- const locationServicesRequestStatus = await requestEnableLocationServices();
29
- const googlePlayServicesRequestStatus = Platform.OS === 'android' ? await requestEnableGooglePlayServices() : true;
29
+ const locationServicesRequestStatus = Platform.OS === 'ios' ? true : await requestEnableLocationServices();
30
+ const gPlayServices = Platform.OS === 'android' ? await requestEnableGooglePlayServices() : true;
30
31
  const locationPermStatus = await requestLocationPermission();
31
- resolve(locationServicesRequestStatus && googlePlayServicesRequestStatus && locationPermStatus);
32
+ resolve(locationServicesRequestStatus && gPlayServices && locationPermStatus);
32
33
  }
33
34
  });
34
35
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["Helpers.ts"],"names":["Platform","isLocationServicesEnabled","isLocationPermissionGranted","isGooglePlayServicesAvailable","requestEnableLocationServices","requestEnableGooglePlayServices","requestLocationPermission","OkHiException","canStartAddressCreation","configuration","Promise","resolve","reject","requestServices","locationServicesStatus","googlePlayServices","OS","locationPerm","code","SERVICE_UNAVAILABLE_CODE","message","locationServicesRequestStatus","googlePlayServicesRequestStatus","locationPermStatus"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SACEC,yBADF,EAEEC,2BAFF,EAGEC,6BAHF,EAIEC,6BAJF,EAKEC,+BALF,EAMEC,yBANF,QAOO,mBAPP;AAQA,SAASC,aAAT,QAA8B,yBAA9B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAIC,aAAD,IAEf;AACtB,SAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;AAC5C,UAAMC,eAAe,GAAGJ,aAAa,IAAIA,aAAa,CAACI,eAAvD;AACA,UAAMC,sBAAsB,GAAG,MAAMb,yBAAyB,EAA9D;AACA,UAAMc,kBAAkB,GACtBf,QAAQ,CAACgB,EAAT,KAAgB,SAAhB,GAA4B,MAAMb,6BAA6B,EAA/D,GAAoE,IADtE;AAEA,UAAMc,YAAY,GAAG,MAAMf,2BAA2B,EAAtD;;AACA,QAAI,CAACW,eAAL,EAAsB;AACpBF,MAAAA,OAAO,CAACG,sBAAsB,IAAIC,kBAA1B,IAAgDE,YAAjD,CAAP;AACD;;AACD,QAAI,CAACH,sBAAD,IAA2Bd,QAAQ,CAACgB,EAAT,KAAgB,KAA/C,EAAsD;AACpDJ,MAAAA,MAAM,CACJ,IAAIL,aAAJ,CAAkB;AAChBW,QAAAA,IAAI,EAAEX,aAAa,CAACY,wBADJ;AAEhBC,QAAAA,OAAO,EAAE;AAFO,OAAlB,CADI,CAAN;AAMD,KAPD,MAOO;AACL,YAAMC,6BAA6B,GAChC,MAAMjB,6BAA6B,EADtC;AAEA,YAAMkB,+BAA+B,GACnCtB,QAAQ,CAACgB,EAAT,KAAgB,SAAhB,GACI,MAAMX,+BAA+B,EADzC,GAEI,IAHN;AAIA,YAAMkB,kBAAkB,GAAG,MAAMjB,yBAAyB,EAA1D;AACAK,MAAAA,OAAO,CACLU,6BAA6B,IAC3BC,+BADF,IAEEC,kBAHG,CAAP;AAKD;AACF,GA9BM,CAAP;AA+BD,CAlCM","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isLocationServicesEnabled,\n isLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n requestEnableLocationServices,\n requestEnableGooglePlayServices,\n requestLocationPermission,\n} from '../OkCore/Helpers';\nimport { OkHiException } from '../OkCore/OkHiException';\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address creation process.\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user.\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user.\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address creation process.\n */\nexport const canStartAddressCreation = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const locationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(locationServicesStatus && googlePlayServices && locationPerm);\n }\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n (await requestEnableLocationServices()) as boolean;\n const googlePlayServicesRequestStatus =\n Platform.OS === 'android'\n ? await requestEnableGooglePlayServices()\n : true;\n const locationPermStatus = await requestLocationPermission();\n resolve(\n locationServicesRequestStatus &&\n googlePlayServicesRequestStatus &&\n locationPermStatus\n );\n }\n });\n};\n"]}
1
+ {"version":3,"sources":["Helpers.ts"],"names":["Platform","isLocationServicesEnabled","isLocationPermissionGranted","isGooglePlayServicesAvailable","requestEnableLocationServices","requestEnableGooglePlayServices","requestLocationPermission","OkHiException","canStartAddressCreation","configuration","Promise","resolve","reject","requestServices","locationServicesStatus","googlePlayServices","OS","locationPerm","code","SERVICE_UNAVAILABLE_CODE","message","locationServicesRequestStatus","gPlayServices","locationPermStatus"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SACEC,yBADF,EAEEC,2BAFF,EAGEC,6BAHF,EAIEC,6BAJF,EAKEC,+BALF,EAMEC,yBANF,QAOO,mBAPP;AAQA,SAASC,aAAT,QAA8B,yBAA9B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAIC,aAAD,IAEf;AACtB,SAAO,IAAIC,OAAJ,CAAY,OAAOC,OAAP,EAAgBC,MAAhB,KAA2B;AAC5C,UAAMC,eAAe,GAAGJ,aAAa,IAAIA,aAAa,CAACI,eAAvD;AACA,UAAMC,sBAAsB,GAAG,MAAMb,yBAAyB,EAA9D;AACA,UAAMc,kBAAkB,GACtBf,QAAQ,CAACgB,EAAT,KAAgB,SAAhB,GAA4B,MAAMb,6BAA6B,EAA/D,GAAoE,IADtE;AAEA,UAAMc,YAAY,GAAG,MAAMf,2BAA2B,EAAtD;;AACA,QAAI,CAACW,eAAL,EAAsB;AACpBF,MAAAA,OAAO,CAACG,sBAAsB,IAAIC,kBAA1B,IAAgDE,YAAjD,CAAP;AACA;AACD;;AACD,QAAI,CAACH,sBAAD,IAA2Bd,QAAQ,CAACgB,EAAT,KAAgB,KAA/C,EAAsD;AACpDJ,MAAAA,MAAM,CACJ,IAAIL,aAAJ,CAAkB;AAChBW,QAAAA,IAAI,EAAEX,aAAa,CAACY,wBADJ;AAEhBC,QAAAA,OAAO,EAAE;AAFO,OAAlB,CADI,CAAN;AAMD,KAPD,MAOO;AACL,YAAMC,6BAA6B,GACjCrB,QAAQ,CAACgB,EAAT,KAAgB,KAAhB,GACI,IADJ,GAEM,MAAMZ,6BAA6B,EAH3C;AAIA,YAAMkB,aAAa,GACjBtB,QAAQ,CAACgB,EAAT,KAAgB,SAAhB,GACI,MAAMX,+BAA+B,EADzC,GAEI,IAHN;AAIA,YAAMkB,kBAAkB,GAAG,MAAMjB,yBAAyB,EAA1D;AACAK,MAAAA,OAAO,CACLU,6BAA6B,IAAIC,aAAjC,IAAkDC,kBAD7C,CAAP;AAGD;AACF,GA/BM,CAAP;AAgCD,CAnCM","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isLocationServicesEnabled,\n isLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n requestEnableLocationServices,\n requestEnableGooglePlayServices,\n requestLocationPermission,\n} from '../OkCore/Helpers';\nimport { OkHiException } from '../OkCore/OkHiException';\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address creation process.\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user.\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user.\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address creation process.\n */\nexport const canStartAddressCreation = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const locationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(locationServicesStatus && googlePlayServices && locationPerm);\n return;\n }\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n Platform.OS === 'ios'\n ? true\n : ((await requestEnableLocationServices()) as boolean);\n const gPlayServices =\n Platform.OS === 'android'\n ? await requestEnableGooglePlayServices()\n : true;\n const locationPermStatus = await requestLocationPermission();\n resolve(\n locationServicesRequestStatus && gPlayServices && locationPermStatus\n );\n }\n });\n};\n"]}
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.0.5"
3
+ "version": "9"
4
4
  }
@@ -107,8 +107,11 @@ export const canStartVerification = configuration => {
107
107
 
108
108
  if (!requestServices) {
109
109
  resolve(locationServicesStatus && googlePlayServices && backgroundLocationPerm);
110
+ return;
110
111
  }
111
112
 
113
+ console.log('here..', requestServices);
114
+
112
115
  if (!locationServicesStatus && Platform.OS === 'ios') {
113
116
  reject(new OkHiException({
114
117
  code: OkHiException.SERVICE_UNAVAILABLE_CODE,
@@ -116,10 +119,16 @@ export const canStartVerification = configuration => {
116
119
  }));
117
120
  } else {
118
121
  const locationServicesRequestStatus = Platform.OS === 'ios' ? true : await requestEnableLocationServices();
119
- const googlePlayServicesRequestStatus = Platform.OS === 'android' ? await requestEnableGooglePlayServices() : true;
120
- const whenInUseLocationRequestStatus = await requestLocationPermission();
121
- const backgroundLocationRequestStatus = await requestBackgroundLocationPermission();
122
- resolve(locationServicesRequestStatus && googlePlayServicesRequestStatus && whenInUseLocationRequestStatus && backgroundLocationRequestStatus);
122
+ const gPlayServices = Platform.OS === 'ios' ? true : await requestEnableGooglePlayServices();
123
+ let perm = false;
124
+
125
+ if (Platform.OS === 'ios') {
126
+ perm = await requestBackgroundLocationPermission();
127
+ } else {
128
+ perm = (await requestLocationPermission()) && (await requestBackgroundLocationPermission());
129
+ }
130
+
131
+ resolve(locationServicesRequestStatus && gPlayServices && perm);
123
132
  }
124
133
  });
125
134
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["Platform","isBackgroundLocationPermissionGranted","isGooglePlayServicesAvailable","isLocationServicesEnabled","requestBackgroundLocationPermission","requestEnableGooglePlayServices","requestEnableLocationServices","requestLocationPermission","errorHandler","isValidPlatform","OkHiNativeModule","OkHiException","start","phoneNumber","locationId","lat","lon","configuration","OS","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","googlePlayServices","backgroundLocationPerm","SERVICE_UNAVAILABLE_CODE","locationServicesRequestStatus","googlePlayServicesRequestStatus","whenInUseLocationRequestStatus","backgroundLocationRequestStatus"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SACEC,qCADF,EAEEC,6BAFF,EAGEC,yBAHF,EAIEC,mCAJF,EAKEC,+BALF,EAMEC,6BANF,EAOEC,yBAPF,QAQO,mBARP;AASA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,oBAA9C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAGA,SAASC,aAAT,QAA8B,yBAA9B;AACA,cAAc,SAAd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,KAMhB;AACH,SAAOR,eAAe,CAAC,MAAM;AAC3B,QAAIT,QAAQ,CAACkB,EAAT,KAAgB,SAApB,EAA+B;AAC7B,aAAOR,gBAAgB,CAACS,wBAAjB,CACLN,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aALK,CAAP;AAOD,KARD,MAQO;AACL,aAAOP,gBAAgB,CAACS,wBAAjB,CACLN,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,CAAP;AAMD;AACF,GAjBqB,CAAtB;AAkBD,CAzBM;AA2BP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMI,iBAAiB,GAAG,OAC/BC,QAD+B,EAE/BJ,aAF+B,KAG5B;AACH,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ACkB,EAAT,KAAgB,SAAhB,GACI,MAAMb,+BAA+B,EADzC,GAEI,IAHN;AAIA,YAAMyC,8BAA8B,GAAG,MAAMvC,yBAAyB,EAAtE;AACA,YAAMwC,+BAA+B,GACnC,MAAM3C,mCAAmC,EAD3C;AAEAmB,MAAAA,OAAO,CACLqB,6BAA6B,IAC3BC,+BADF,IAEEC,8BAFF,IAGEC,+BAJG,CAAP;AAMD;AACF,GAtCM,CAAP;AAuCD,CA1CM","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n} from '../OkCore/Helpers';\nimport { errorHandler, isValidPlatform } from '../OkCore/_helpers';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkVerifyStartConfiguration } from './types';\nimport type { OkCollectSuccessResponse } from '../OkCollect/types';\nimport { OkHiException } from '../OkCore/OkHiException';\nexport * from './types';\n/**\n * Starts verification for a particular address\n * @param {string} phoneNumber A users phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @param {number} lat The latitude of the created address\n * @param {number} lon The longitude of the created address\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const start = (\n phoneNumber: string,\n locationId: string,\n lat: number,\n lon: number,\n configuration?: OkVerifyStartConfiguration\n) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration\n );\n } else {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon\n );\n }\n });\n};\n\n/**\n * Starts verification for a particular address using the response object returned by OkCollect\n * @param {Object} response Response returned by OkCollect\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const startVerification = async (\n response: OkCollectSuccessResponse,\n configuration?: OkVerifyStartConfiguration\n) => {\n return new Promise((resolve, reject) => {\n const { location, user } = response;\n if (location.id) {\n if (Platform.OS === 'android') {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon,\n configuration\n );\n resolve(result);\n } else {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon\n );\n resolve(result);\n }\n } else {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n }\n });\n};\n\n/**\n * Stops verification for a particular address using a user's phonenumber and OkHi location identifier\n * @param {string} phoneNumber The user's phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const stopVerification = (phoneNumber: string, locationId: string) => {\n return isValidPlatform(() =>\n OkHiNativeModule.stopAddressVerification(phoneNumber, locationId)\n );\n};\n\n/**\n * Android Only - Starts a foreground service that speeds up rate of verification\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const startForegroundService = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.startForegroundService),\n 'android'\n );\n};\n\n/**\n * Android Only - Stops previously started foreground services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has stopped successfully\n */\nexport const stopForegroundService = () => {\n return isValidPlatform(OkHiNativeModule.stopForegroundService, 'android');\n};\n\n/**\n * Android Only - Checks if the foreground service is running\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is running\n */\nexport const isForegroundServiceRunning = () => {\n return isValidPlatform(\n OkHiNativeModule.isForegroundServiceRunning,\n 'android'\n );\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const canStartVerification = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const backgroundLocationPerm =\n await isBackgroundLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n }\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n Platform.OS === 'ios'\n ? true\n : ((await requestEnableLocationServices()) as boolean);\n const googlePlayServicesRequestStatus =\n Platform.OS === 'android'\n ? await requestEnableGooglePlayServices()\n : true;\n const whenInUseLocationRequestStatus = await requestLocationPermission();\n const backgroundLocationRequestStatus =\n await requestBackgroundLocationPermission();\n resolve(\n locationServicesRequestStatus &&\n googlePlayServicesRequestStatus &&\n whenInUseLocationRequestStatus &&\n backgroundLocationRequestStatus\n );\n }\n });\n};\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["Platform","isBackgroundLocationPermissionGranted","isGooglePlayServicesAvailable","isLocationServicesEnabled","requestBackgroundLocationPermission","requestEnableGooglePlayServices","requestEnableLocationServices","requestLocationPermission","errorHandler","isValidPlatform","OkHiNativeModule","OkHiException","start","phoneNumber","locationId","lat","lon","configuration","OS","startAddressVerification","startVerification","response","Promise","resolve","reject","location","user","id","result","phone","code","BAD_REQUEST_CODE","message","stopVerification","stopAddressVerification","startForegroundService","stopForegroundService","isForegroundServiceRunning","canStartVerification","requestServices","locationServicesStatus","googlePlayServices","backgroundLocationPerm","console","log","SERVICE_UNAVAILABLE_CODE","locationServicesRequestStatus","gPlayServices","perm"],"mappings":"AAAA,SAASA,QAAT,QAAyB,cAAzB;AACA,SACEC,qCADF,EAEEC,6BAFF,EAGEC,yBAHF,EAIEC,mCAJF,EAKEC,+BALF,EAMEC,6BANF,EAOEC,yBAPF,QAQO,mBARP;AASA,SAASC,YAAT,EAAuBC,eAAvB,QAA8C,oBAA9C;AACA,SAASC,gBAAT,QAAiC,qBAAjC;AAGA,SAASC,aAAT,QAA8B,yBAA9B;AACA,cAAc,SAAd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAG,CACnBC,WADmB,EAEnBC,UAFmB,EAGnBC,GAHmB,EAInBC,GAJmB,EAKnBC,aALmB,KAMhB;AACH,SAAOR,eAAe,CAAC,MAAM;AAC3B,QAAIT,QAAQ,CAACkB,EAAT,KAAgB,SAApB,EAA+B;AAC7B,aAAOR,gBAAgB,CAACS,wBAAjB,CACLN,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,EAKLC,aALK,CAAP;AAOD,KARD,MAQO;AACL,aAAOP,gBAAgB,CAACS,wBAAjB,CACLN,WADK,EAELC,UAFK,EAGLC,GAHK,EAILC,GAJK,CAAP;AAMD;AACF,GAjBqB,CAAtB;AAkBD,CAzBM;AA2BP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMI,iBAAiB,GAAG,OAC/BC,QAD+B,EAE/BJ,aAF+B,KAG5B;AACH,SAAO,IAAIK,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtC,UAAM;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,QAAqBL,QAA3B;;AACA,QAAII,QAAQ,CAACE,EAAb,EAAiB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AACA,UAAIhD,QAAQ,CAACkB,EAAT,KAAgB,KAApB,EAA2B;AACzB8B,QAAAA,IAAI,GAAG,MAAM5C,mCAAmC,EAAhD;AACD,OAFD,MAEO;AACL4C,QAAAA,IAAI,GACF,CAAC,MAAMzC,yBAAyB,EAAhC,MACC,MAAMH,mCAAmC,EAD1C,CADF;AAGD;;AACDmB,MAAAA,OAAO,CAACuB,6BAA6B,IAAIC,aAAjC,IAAkDC,IAAnD,CAAP;AACD;AACF,GAtCM,CAAP;AAuCD,CA1CM","sourcesContent":["import { Platform } from 'react-native';\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n} from '../OkCore/Helpers';\nimport { errorHandler, isValidPlatform } from '../OkCore/_helpers';\nimport { OkHiNativeModule } from '../OkHiNativeModule';\nimport type { OkVerifyStartConfiguration } from './types';\nimport type { OkCollectSuccessResponse } from '../OkCollect/types';\nimport { OkHiException } from '../OkCore/OkHiException';\nexport * from './types';\n/**\n * Starts verification for a particular address\n * @param {string} phoneNumber A users phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @param {number} lat The latitude of the created address\n * @param {number} lon The longitude of the created address\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification, default is true\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const start = (\n phoneNumber: string,\n locationId: string,\n lat: number,\n lon: number,\n configuration?: OkVerifyStartConfiguration\n) => {\n return isValidPlatform(() => {\n if (Platform.OS === 'android') {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon,\n configuration\n );\n } else {\n return OkHiNativeModule.startAddressVerification(\n phoneNumber,\n locationId,\n lat,\n lon\n );\n }\n });\n};\n\n/**\n * Starts verification for a particular address using the response object returned by OkCollect\n * @param {Object} response Response returned by OkCollect\n * @param {Object} configuration Configures how verification will start on different platforms\n * @param {Object} configuration.android Specifices how verification will start on Android platforms\n * @param {boolean} configuration.android.withForeground Specifices if the foreground service will be turned on to speed up rate of verification\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const startVerification = async (\n response: OkCollectSuccessResponse,\n configuration?: OkVerifyStartConfiguration\n) => {\n return new Promise((resolve, reject) => {\n const { location, user } = response;\n if (location.id) {\n if (Platform.OS === 'android') {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon,\n configuration\n );\n resolve(result);\n } else {\n const result = OkHiNativeModule.startAddressVerification(\n user.phone,\n location.id,\n location.lat,\n location.lon\n );\n resolve(result);\n }\n } else {\n reject(\n new OkHiException({\n code: OkHiException.BAD_REQUEST_CODE,\n message: 'Missing location id from response',\n })\n );\n }\n });\n};\n\n/**\n * Stops verification for a particular address using a user's phonenumber and OkHi location identifier\n * @param {string} phoneNumber The user's phone number\n * @param {string} locationId An OkHi location identifier obtained after successfull creation of addresses.\n * @returns {Promise<string>} A promise that resolves to a string value of the location identifier\n */\nexport const stopVerification = (phoneNumber: string, locationId: string) => {\n return isValidPlatform(() =>\n OkHiNativeModule.stopAddressVerification(phoneNumber, locationId)\n );\n};\n\n/**\n * Android Only - Starts a foreground service that speeds up rate of verification\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has started successfully\n */\nexport const startForegroundService = () => {\n return isValidPlatform(\n () => errorHandler(OkHiNativeModule.startForegroundService),\n 'android'\n );\n};\n\n/**\n * Android Only - Stops previously started foreground services\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service has stopped successfully\n */\nexport const stopForegroundService = () => {\n return isValidPlatform(OkHiNativeModule.stopForegroundService, 'android');\n};\n\n/**\n * Android Only - Checks if the foreground service is running\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether the service is running\n */\nexport const isForegroundServiceRunning = () => {\n return isValidPlatform(\n OkHiNativeModule.isForegroundServiceRunning,\n 'android'\n );\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\n * @param {Object} configuration Object that determines whether or not to request these permissions and services from the user\n * @param {boolean} configuration.requestServices Flag that determines whether to request the services from the user\n * @returns {Promise<boolean>} A promise that resolves to a boolean value indicating whether or not all conditions are met to start the address verification process\n */\nexport const canStartVerification = (configuration?: {\n requestServices?: boolean;\n}): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n const requestServices = configuration && configuration.requestServices;\n const locationServicesStatus = await isLocationServicesEnabled();\n const googlePlayServices =\n Platform.OS === 'android' ? await isGooglePlayServicesAvailable() : true;\n const backgroundLocationPerm =\n await isBackgroundLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n return;\n }\n console.log('here..', requestServices);\n if (!locationServicesStatus && Platform.OS === 'ios') {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n } else {\n const locationServicesRequestStatus =\n Platform.OS === 'ios'\n ? true\n : ((await requestEnableLocationServices()) as boolean);\n const gPlayServices =\n Platform.OS === 'ios' ? true : await requestEnableGooglePlayServices();\n let perm = false;\n if (Platform.OS === 'ios') {\n perm = await requestBackgroundLocationPermission();\n } else {\n perm =\n (await requestLocationPermission()) &&\n (await requestBackgroundLocationPermission());\n }\n resolve(locationServicesRequestStatus && gPlayServices && perm);\n }\n });\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-okhi",
3
- "version": "1.0.5",
3
+ "version": "1.0.9",
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",
@@ -26,6 +26,7 @@ export const canStartAddressCreation = (configuration?: {
26
26
  const locationPerm = await isLocationPermissionGranted();
27
27
  if (!requestServices) {
28
28
  resolve(locationServicesStatus && googlePlayServices && locationPerm);
29
+ return;
29
30
  }
30
31
  if (!locationServicesStatus && Platform.OS === 'ios') {
31
32
  reject(
@@ -36,16 +37,16 @@ export const canStartAddressCreation = (configuration?: {
36
37
  );
37
38
  } else {
38
39
  const locationServicesRequestStatus =
39
- (await requestEnableLocationServices()) as boolean;
40
- const googlePlayServicesRequestStatus =
40
+ Platform.OS === 'ios'
41
+ ? true
42
+ : ((await requestEnableLocationServices()) as boolean);
43
+ const gPlayServices =
41
44
  Platform.OS === 'android'
42
45
  ? await requestEnableGooglePlayServices()
43
46
  : true;
44
47
  const locationPermStatus = await requestLocationPermission();
45
48
  resolve(
46
- locationServicesRequestStatus &&
47
- googlePlayServicesRequestStatus &&
48
- locationPermStatus
49
+ locationServicesRequestStatus && gPlayServices && locationPermStatus
49
50
  );
50
51
  }
51
52
  });
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "okhiWebReactNative",
3
- "version": "1.0.5"
3
+ "version": "9"
4
4
  }
@@ -158,7 +158,9 @@ export const canStartVerification = (configuration?: {
158
158
  resolve(
159
159
  locationServicesStatus && googlePlayServices && backgroundLocationPerm
160
160
  );
161
+ return;
161
162
  }
163
+ console.log('here..', requestServices);
162
164
  if (!locationServicesStatus && Platform.OS === 'ios') {
163
165
  reject(
164
166
  new OkHiException({
@@ -171,19 +173,17 @@ export const canStartVerification = (configuration?: {
171
173
  Platform.OS === 'ios'
172
174
  ? true
173
175
  : ((await requestEnableLocationServices()) as boolean);
174
- const googlePlayServicesRequestStatus =
175
- Platform.OS === 'android'
176
- ? await requestEnableGooglePlayServices()
177
- : true;
178
- const whenInUseLocationRequestStatus = await requestLocationPermission();
179
- const backgroundLocationRequestStatus =
180
- await requestBackgroundLocationPermission();
181
- resolve(
182
- locationServicesRequestStatus &&
183
- googlePlayServicesRequestStatus &&
184
- whenInUseLocationRequestStatus &&
185
- backgroundLocationRequestStatus
186
- );
176
+ const gPlayServices =
177
+ Platform.OS === 'ios' ? true : await requestEnableGooglePlayServices();
178
+ let perm = false;
179
+ if (Platform.OS === 'ios') {
180
+ perm = await requestBackgroundLocationPermission();
181
+ } else {
182
+ perm =
183
+ (await requestLocationPermission()) &&
184
+ (await requestBackgroundLocationPermission());
185
+ }
186
+ resolve(locationServicesRequestStatus && gPlayServices && perm);
187
187
  }
188
188
  });
189
189
  };