react-native-okhi 1.0.13-beta.3 → 1.0.13-beta.6
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/android/src/main/java/com/reactnativeokhi/OkhiModule.java +11 -0
- package/ios/Okhi-Bridging-Header.h +1 -0
- package/ios/Okhi.m +4 -1
- package/ios/Okhi.swift +43 -11
- package/ios/Okhi.xcodeproj/project.xcworkspace/xcuserdata/kiano.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/OkCore/Helpers.js +53 -1
- package/lib/commonjs/OkCore/Helpers.js.map +1 -1
- package/lib/commonjs/OkCore/OkHiException.js +12 -0
- package/lib/commonjs/OkCore/OkHiException.js.map +1 -1
- package/lib/commonjs/OkHiNativeModule/index.js +3 -1
- package/lib/commonjs/OkHiNativeModule/index.js.map +1 -1
- package/lib/commonjs/OkVerify/index.js +73 -15
- package/lib/commonjs/OkVerify/index.js.map +1 -1
- package/lib/module/OkCore/Helpers.js +47 -2
- package/lib/module/OkCore/Helpers.js.map +1 -1
- package/lib/module/OkCore/OkHiException.js +12 -0
- package/lib/module/OkCore/OkHiException.js.map +1 -1
- package/lib/module/OkHiNativeModule/index.js +2 -1
- package/lib/module/OkHiNativeModule/index.js.map +1 -1
- package/lib/module/OkVerify/index.js +67 -13
- package/lib/module/OkVerify/index.js.map +1 -1
- package/lib/typescript/OkCore/Helpers.d.ts +12 -0
- package/lib/typescript/OkCore/OkHiException.d.ts +8 -0
- package/lib/typescript/OkHiNativeModule/index.d.ts +3 -0
- package/lib/typescript/OkVerify/index.d.ts +5 -0
- package/package.json +1 -1
- package/react-native-okhi.podspec +1 -2
- package/src/OkCore/Helpers.ts +81 -2
- package/src/OkCore/OkHiException.ts +9 -0
- package/src/OkHiNativeModule/index.ts +4 -1
- package/src/OkVerify/index.ts +73 -18
- package/android/.idea/gradle.xml +0 -19
- package/android/.idea/misc.xml +0 -9
- package/android/.idea/modules/android.iml +0 -18
- package/android/.idea/modules.xml +0 -8
- package/android/.idea/vcs.xml +0 -6
- package/android/.idea/workspace.xml +0 -42
|
@@ -3,7 +3,9 @@ package com.reactnativeokhi;
|
|
|
3
3
|
import android.app.Activity;
|
|
4
4
|
import android.app.NotificationManager;
|
|
5
5
|
import android.content.Intent;
|
|
6
|
+
import android.net.Uri;
|
|
6
7
|
import android.os.Build;
|
|
8
|
+
import android.provider.Settings;
|
|
7
9
|
import android.util.Base64;
|
|
8
10
|
|
|
9
11
|
import androidx.annotation.NonNull;
|
|
@@ -247,6 +249,15 @@ public class OkhiModule extends ReactContextBaseJavaModule {
|
|
|
247
249
|
promise.resolve(result);
|
|
248
250
|
}
|
|
249
251
|
|
|
252
|
+
@ReactMethod
|
|
253
|
+
public void openAppSettings(Promise promise) {
|
|
254
|
+
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
255
|
+
Uri uri = Uri.fromParts("package", getReactApplicationContext().getPackageName(), null);
|
|
256
|
+
intent.setData(uri);
|
|
257
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
258
|
+
getReactApplicationContext().startActivity(intent);
|
|
259
|
+
}
|
|
260
|
+
|
|
250
261
|
private Dynamic getConfig(ReadableMap map, String prop) {
|
|
251
262
|
if (map != null && map.hasKey("android")) {
|
|
252
263
|
ReadableMap config = map.getMap("android");
|
package/ios/Okhi.m
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import "React/RCTEventEmitter.h"
|
|
2
3
|
|
|
3
|
-
@interface RCT_EXTERN_MODULE(Okhi,
|
|
4
|
+
@interface RCT_EXTERN_MODULE(Okhi, RCTEventEmitter)
|
|
4
5
|
|
|
5
6
|
RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
|
|
6
7
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
@@ -18,6 +19,8 @@ RCT_EXTERN_METHOD(requestBackgroundLocationPermission: (RCTPromiseResolveBlock)r
|
|
|
18
19
|
|
|
19
20
|
RCT_EXTERN_METHOD(requestEnableLocationServices: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
20
21
|
|
|
22
|
+
RCT_EXTERN_METHOD(openAppSettings: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
23
|
+
|
|
21
24
|
RCT_EXTERN_METHOD(getSystemVersion: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
|
22
25
|
|
|
23
26
|
RCT_EXTERN_METHOD(getApplicationConfiguration: (RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
|
package/ios/Okhi.swift
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import UIKit
|
|
2
|
-
import
|
|
2
|
+
import OkHi
|
|
3
3
|
import CoreLocation
|
|
4
4
|
|
|
5
5
|
@objc(Okhi)
|
|
6
|
-
class Okhi:
|
|
6
|
+
class Okhi: RCTEventEmitter {
|
|
7
7
|
private enum LocationPermissionRequestType: String {
|
|
8
8
|
case whenInUse = "whenInUse"
|
|
9
9
|
case always = "always"
|
|
@@ -11,15 +11,15 @@ class Okhi: NSObject {
|
|
|
11
11
|
private var currentLocationPermissionRequestType: LocationPermissionRequestType = .always
|
|
12
12
|
private var resolve: RCTPromiseResolveBlock?
|
|
13
13
|
private var reject: RCTPromiseRejectBlock?
|
|
14
|
-
private var okVerify:
|
|
14
|
+
private var okVerify: OkVerify
|
|
15
15
|
|
|
16
16
|
override init() {
|
|
17
|
-
okVerify =
|
|
17
|
+
okVerify = OkVerify()
|
|
18
18
|
super.init()
|
|
19
19
|
okVerify.delegate = self
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
override static func requiresMainQueueSetup() -> Bool {
|
|
23
23
|
return false
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -57,7 +57,14 @@ class Okhi: NSObject {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
@objc func requestEnableLocationServices(_ resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
60
|
-
|
|
60
|
+
if let url = URL.init(string: UIApplication.openSettingsURLString) {
|
|
61
|
+
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
62
|
+
}
|
|
63
|
+
resolve(NSNull())
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@objc func openAppSettings(_ resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) {
|
|
67
|
+
OkVerify.openAppSettings()
|
|
61
68
|
resolve(NSNull())
|
|
62
69
|
}
|
|
63
70
|
|
|
@@ -82,6 +89,10 @@ class Okhi: NSObject {
|
|
|
82
89
|
self.reject = reject
|
|
83
90
|
okVerify.stopAddressVerification(locationId: locationId)
|
|
84
91
|
}
|
|
92
|
+
|
|
93
|
+
override func supportedEvents() -> [String]! {
|
|
94
|
+
return ["onLocationPermissionStatusUpdate"]
|
|
95
|
+
}
|
|
85
96
|
}
|
|
86
97
|
|
|
87
98
|
// MARK: - OkHi Utils
|
|
@@ -97,7 +108,28 @@ extension Okhi {
|
|
|
97
108
|
|
|
98
109
|
// MARK: - OkVerify Delegates
|
|
99
110
|
extension Okhi: OkVerifyDelegate {
|
|
100
|
-
func verify(_ okverify:
|
|
111
|
+
func verify(_ okverify: OkVerify, didUpdateLocationPermissionStatus status: CLAuthorizationStatus) {
|
|
112
|
+
var str: String = ""
|
|
113
|
+
switch status {
|
|
114
|
+
case .notDetermined:
|
|
115
|
+
str = "notDetermined"
|
|
116
|
+
case .restricted:
|
|
117
|
+
str = "restricted"
|
|
118
|
+
case .denied:
|
|
119
|
+
str = "denied"
|
|
120
|
+
case .authorizedAlways:
|
|
121
|
+
str = "authorizedAlways"
|
|
122
|
+
case .authorizedWhenInUse:
|
|
123
|
+
str = "authorizedWhenInUse"
|
|
124
|
+
case .authorized:
|
|
125
|
+
str = "authorized"
|
|
126
|
+
@unknown default:
|
|
127
|
+
str = "unknown"
|
|
128
|
+
}
|
|
129
|
+
sendEvent(withName: "onLocationPermissionStatusUpdate", body: str)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
func verify(_ okverify: OkVerify, didChangeLocationPermissionStatus requestType: OkVerifyLocationPermissionRequestType, status: Bool) {
|
|
101
133
|
if let resolve = self.resolve {
|
|
102
134
|
if currentLocationPermissionRequestType == .whenInUse && requestType == .whenInUse {
|
|
103
135
|
resolve(status)
|
|
@@ -109,25 +141,25 @@ extension Okhi: OkVerifyDelegate {
|
|
|
109
141
|
}
|
|
110
142
|
}
|
|
111
143
|
|
|
112
|
-
func verify(_ okverify:
|
|
144
|
+
func verify(_ okverify: OkVerify, didInitialize result: Bool) {
|
|
113
145
|
guard let resolve = resolve else { return }
|
|
114
146
|
resolve(result)
|
|
115
147
|
self.resolve = nil
|
|
116
148
|
}
|
|
117
149
|
|
|
118
|
-
func verify(_ okverify:
|
|
150
|
+
func verify(_ okverify: OkVerify, didEncounterError error: OkVerifyError) {
|
|
119
151
|
guard let reject = reject else { return }
|
|
120
152
|
reject(error.code, error.message, error)
|
|
121
153
|
self.reject = nil
|
|
122
154
|
}
|
|
123
155
|
|
|
124
|
-
func verify(_ okverify:
|
|
156
|
+
func verify(_ okverify: OkVerify, didStartAddressVerificationFor locationId: String) {
|
|
125
157
|
guard let resolve = resolve else { return }
|
|
126
158
|
resolve(locationId)
|
|
127
159
|
self.resolve = nil
|
|
128
160
|
}
|
|
129
161
|
|
|
130
|
-
func verify(_ okverify:
|
|
162
|
+
func verify(_ okverify: OkVerify, didStopVerificationFor locationId: String) {
|
|
131
163
|
guard let resolve = resolve else { return }
|
|
132
164
|
resolve(locationId)
|
|
133
165
|
self.resolve = nil
|
|
Binary file
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.requestLocationPermission = exports.requestEnableLocationServices = exports.requestEnableGooglePlayServices = exports.requestBackgroundLocationPermission = exports.isLocationServicesEnabled = exports.isLocationPermissionGranted = exports.isGooglePlayServicesAvailable = exports.isBackgroundLocationPermissionGranted = exports.getSystemVersion = void 0;
|
|
6
|
+
exports.requestLocationPermission = exports.requestEnableLocationServices = exports.requestEnableGooglePlayServices = exports.requestBackgroundLocationPermission = exports.request = exports.openAppSettings = exports.isLocationServicesEnabled = exports.isLocationPermissionGranted = exports.isGooglePlayServicesAvailable = exports.isBackgroundLocationPermissionGranted = exports.getSystemVersion = void 0;
|
|
7
7
|
|
|
8
8
|
var _OkHiNativeModule = require("../OkHiNativeModule");
|
|
9
9
|
|
|
@@ -78,6 +78,7 @@ const requestLocationPermissionIOS = () => {
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
const requestLocationPermission = async () => {
|
|
81
|
+
console.log('yooo');
|
|
81
82
|
const isGranted = await isLocationPermissionGranted();
|
|
82
83
|
if (isGranted) return isGranted;
|
|
83
84
|
return (0, _helpers.errorHandler)(_reactNative.Platform.OS === 'android' ? requestLocationPermissionAndroid : requestLocationPermissionIOS);
|
|
@@ -156,4 +157,55 @@ exports.requestEnableGooglePlayServices = requestEnableGooglePlayServices;
|
|
|
156
157
|
const getSystemVersion = () => (0, _helpers.isValidPlatform)(_OkHiNativeModule.OkHiNativeModule.getSystemVersion);
|
|
157
158
|
|
|
158
159
|
exports.getSystemVersion = getSystemVersion;
|
|
160
|
+
|
|
161
|
+
const request = (locationPermissionType, rationale, callback) => {
|
|
162
|
+
if (_reactNative.Platform.OS === 'ios') {
|
|
163
|
+
_OkHiNativeModule.OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');
|
|
164
|
+
|
|
165
|
+
_OkHiNativeModule.OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', callback);
|
|
166
|
+
|
|
167
|
+
if (locationPermissionType === 'whenInUse') {
|
|
168
|
+
_OkHiNativeModule.OkHiNativeModule.requestLocationPermission();
|
|
169
|
+
} else {
|
|
170
|
+
_OkHiNativeModule.OkHiNativeModule.requestBackgroundLocationPermission();
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
if (locationPermissionType === 'whenInUse') {
|
|
174
|
+
requestLocationPermissionAndroid().then(result => callback(result ? 'authorizedWhenInUse' : 'denied'));
|
|
175
|
+
} else {
|
|
176
|
+
requestLocationPermissionAndroid().then(async whenInUseResult => {
|
|
177
|
+
if (whenInUseResult) {
|
|
178
|
+
const version = await getSystemVersion();
|
|
179
|
+
|
|
180
|
+
if (version >= 30 && rationale) {
|
|
181
|
+
_reactNative.Alert.alert(rationale.title, rationale.text, [{
|
|
182
|
+
text: rationale.successButton ? rationale.successButton.label : 'Okay',
|
|
183
|
+
onPress: async () => {
|
|
184
|
+
const result = await requestBackgroundLocationPermission();
|
|
185
|
+
callback(result ? 'authorizedAlways' : 'authorizedWhenInUse');
|
|
186
|
+
}
|
|
187
|
+
}], {
|
|
188
|
+
onDismiss: () => {
|
|
189
|
+
callback('authorizedWhenInUse');
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
const permission = await requestBackgroundLocationPermission();
|
|
194
|
+
callback(permission ? 'authorizedAlways' : 'authorizedWhenInUse');
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
callback('denied');
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
exports.request = request;
|
|
205
|
+
|
|
206
|
+
const openAppSettings = () => {
|
|
207
|
+
_OkHiNativeModule.OkHiNativeModule.openAppSettings();
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
exports.openAppSettings = openAppSettings;
|
|
159
211
|
//# sourceMappingURL=Helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Helpers.ts"],"names":["isLocationServicesEnabled","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","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACO,MAAMA,yBAAyB,GAAG,MAAwB;AAC/D,SAAO,8BAAgBC,mCAAiBD,yBAAjC,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;;;;;AACO,MAAME,2BAA2B,GAAG,MAAwB;AACjE,SAAO,8BAAgBD,mCAAiBC,2BAAjC,CAAP;AACD,CAFM;;;;AAIP,MAAMC,4CAA4C,GAChD,YAA8B;AAC5B,QAAMC,UAAU,GAAG,MAAMH,mCAAiBI,gBAAjB,EAAzB;;AACA,MAAID,UAAU,GAAG,EAAjB,EAAqB;AACnB,WAAO,IAAP;AACD;;AACD,MAAIA,UAAU,GAAG,EAAjB,EAAqB;AACnB,WAAO,MAAMF,2BAA2B,EAAxC;AACD;;AACD,QAAMI,aAAa,GAAG,MAAMC,gCAAmBC,KAAnB,CAC1BD,gCAAmBE,WAAnB,CAA+BC,0BADL,CAA5B;AAGA,SAAOJ,aAAP;AACD,CAbH;;AAeA,MAAMK,wCAAwC,GAAG,MAAwB;AACvE,SAAOV,mCAAiBW,qCAAjB,EAAP;AACD,CAFD;AAIA;AACA;AACA;AACA;;;AACO,MAAMA,qCAAqC,GAAG,MAAwB;AAC3E,QAAMC,EAAE,GACNC,sBAASC,EAAT,KAAgB,SAAhB,GACIZ,4CADJ,GAEIQ,wCAHN;AAIA,SAAO,8BAAgBE,EAAhB,CAAP;AACD,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D;AACA,MAAIW,SAAJ,EAAe,OAAOA,SAAP;AACf,SAAO,2BACLT,sBAASC,EAAT,KAAgB,SAAhB,GACIS,0CADJ,GAEIE,sCAHC,CAAP;AAKD,CATI;AAWP;AACA;AACA;AACA;;;;;AACO,MAAME,6BAA6B,GAAG,MAA+B;AAC1E,SAAO,8BAAgB3B,mCAAiB2B,6BAAjC,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;;;;;AACO,MAAMC,6BAA6B,GAAG,MAAwB;AACnE,SAAO,8BACL5B,mCAAiB4B,6BADZ,EAEL,SAFK,CAAP;AAID,CALM;AAOP;AACA;AACA;AACA;;;;;AACO,MAAMC,+BAA+B,GAAG,MAAwB;AACrE,SAAO,8BACL7B,mCAAiB6B,+BADZ,EAEL,SAFK,CAAP;AAID,CALM;AAOP;AACA;AACA;AACA;;;;;AACO,MAAMzB,gBAAgB,GAAG,MAC9B,8BAAgBJ,mCAAiBI,gBAAjC,CADK","sourcesContent":["import { OkHiNativeModule } from '../OkHiNativeModule';\nimport { PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\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\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,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,\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"]}
|
|
1
|
+
{"version":3,"sources":["Helpers.ts"],"names":["isLocationServicesEnabled","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","console","log","isGranted","requestBackgroundLocationPermissionAndroid","permissions","requestBackgroundLocationPermissionIOS","requestBackgroundLocationPermission","requestEnableLocationServices","isGooglePlayServicesAvailable","requestEnableGooglePlayServices","request","locationPermissionType","rationale","callback","OkHiNativeEvents","removeAllListeners","addListener","then","result","whenInUseResult","version","Alert","alert","title","text","successButton","label","onPress","onDismiss","permission","openAppSettings"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACO,MAAMA,yBAAyB,GAAG,MAAwB;AAC/D,SAAO,8BAAgBC,mCAAiBD,yBAAjC,CAAP;AACD,CAFM;AAIP;AACA;AACA;AACA;;;;;AACO,MAAME,2BAA2B,GAAG,MAAwB;AACjE,SAAO,8BAAgBD,mCAAiBC,2BAAjC,CAAP;AACD,CAFM;;;;AAIP,MAAMC,4CAA4C,GAChD,YAA8B;AAC5B,QAAMC,UAAU,GAAG,MAAMH,mCAAiBI,gBAAjB,EAAzB;;AACA,MAAID,UAAU,GAAG,EAAjB,EAAqB;AACnB,WAAO,IAAP;AACD;;AACD,MAAIA,UAAU,GAAG,EAAjB,EAAqB;AACnB,WAAO,MAAMF,2BAA2B,EAAxC;AACD;;AACD,QAAMI,aAAa,GAAG,MAAMC,gCAAmBC,KAAnB,CAC1BD,gCAAmBE,WAAnB,CAA+BC,0BADL,CAA5B;AAGA,SAAOJ,aAAP;AACD,CAbH;;AAeA,MAAMK,wCAAwC,GAAG,MAAwB;AACvE,SAAOV,mCAAiBW,qCAAjB,EAAP;AACD,CAFD;AAIA;AACA;AACA;AACA;;;AACO,MAAMA,qCAAqC,GAAG,MAAwB;AAC3E,QAAMC,EAAE,GACNC,sBAASC,EAAT,KAAgB,SAAhB,GACIZ,4CADJ,GAEIQ,wCAHN;AAIA,SAAO,8BAAgBE,EAAhB,CAAP;AACD,CANM;;;;AAQP,MAAMG,gCAAgC,GAAG,YAA8B;AACrE,QAAMC,MAAW,GAAG,MAAMV,gCAAmBW,eAAn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cAAIsC,OAAO,IAAI,EAAX,IAAiBR,SAArB,EAAgC;AAC9BS,+BAAMC,KAAN,CACEV,SAAS,CAACW,KADZ,EAEEX,SAAS,CAACY,IAFZ,EAGE,CACE;AACEA,cAAAA,IAAI,EAAEZ,SAAS,CAACa,aAAV,GACFb,SAAS,CAACa,aAAV,CAAwBC,KADtB,GAEF,MAHN;AAIEC,cAAAA,OAAO,EAAE,YAAY;AACnB,sBAAMT,MAAM,GAAG,MAAMZ,mCAAmC,EAAxD;AACAO,gBAAAA,QAAQ,CACNK,MAAM,GAAG,kBAAH,GAAwB,qBADxB,CAAR;AAGD;AATH,aADF,CAHF,EAgBE;AACEU,cAAAA,SAAS,EAAE,MAAM;AACff,gBAAAA,QAAQ,CAAC,qBAAD,CAAR;AACD;AAHH,aAhBF;AAsBD,WAvBD,MAuBO;AACL,kBAAMgB,UAAU,GAAG,MAAMvB,mCAAmC,EAA5D;AACAO,YAAAA,QAAQ,CAACgB,UAAU,GAAG,kBAAH,GAAwB,qBAAnC,CAAR;AACD;AACF,SA7BD,MA6BO;AACLhB,UAAAA,QAAQ,CAAC,QAAD,CAAR;AACD;AACF,OAjCD;AAkCD;AACF;AACF,CA3DM;;;;AA6DA,MAAMiB,eAAe,GAAG,MAAM;AACnCpD,qCAAiBoD,eAAjB;AACD,CAFM","sourcesContent":["import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';\nimport { Alert, PermissionsAndroid, Platform } from 'react-native';\nimport { errorHandler, isValidPlatform } from './_helpers';\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\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,\n PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,\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 console.log('yooo');\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\ntype LocationPermissionStatus =\n | 'notDetermined'\n | 'restricted'\n | 'denied'\n | 'authorizedAlways'\n | 'authorizedWhenInUse'\n | 'authorized'\n | 'unknown';\n\ntype LocationPermissionType = 'whenInUse' | 'always';\n\ntype LocationPermissionCallback = (status: LocationPermissionStatus) => any;\n\nexport const request = (\n locationPermissionType: LocationPermissionType,\n rationale: {\n title: string;\n text: string;\n successButton?: { label: string };\n } | null,\n callback: LocationPermissionCallback\n) => {\n if (Platform.OS === 'ios') {\n OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');\n OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', callback);\n if (locationPermissionType === 'whenInUse') {\n OkHiNativeModule.requestLocationPermission();\n } else {\n OkHiNativeModule.requestBackgroundLocationPermission();\n }\n } else {\n if (locationPermissionType === 'whenInUse') {\n requestLocationPermissionAndroid().then((result) =>\n callback(result ? 'authorizedWhenInUse' : 'denied')\n );\n } else {\n requestLocationPermissionAndroid().then(async (whenInUseResult) => {\n if (whenInUseResult) {\n const version = await getSystemVersion();\n if (version >= 30 && rationale) {\n Alert.alert(\n rationale.title,\n rationale.text,\n [\n {\n text: rationale.successButton\n ? rationale.successButton.label\n : 'Okay',\n onPress: async () => {\n const result = await requestBackgroundLocationPermission();\n callback(\n result ? 'authorizedAlways' : 'authorizedWhenInUse'\n );\n },\n },\n ],\n {\n onDismiss: () => {\n callback('authorizedWhenInUse');\n },\n }\n );\n } else {\n const permission = await requestBackgroundLocationPermission();\n callback(permission ? 'authorizedAlways' : 'authorizedWhenInUse');\n }\n } else {\n callback('denied');\n }\n });\n }\n }\n};\n\nexport const openAppSettings = () => {\n OkHiNativeModule.openAppSettings();\n};\n"]}
|
|
@@ -12,6 +12,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
12
12
|
* It contains static string properties that can be used to evaluate the kind of errors being thrown and handle them appropriately.
|
|
13
13
|
*/
|
|
14
14
|
class OkHiException extends Error {
|
|
15
|
+
/**
|
|
16
|
+
* Error is thrown when location services is unavailable.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Error is thrown when play services is unavailable.
|
|
21
|
+
*/
|
|
22
|
+
|
|
15
23
|
/**
|
|
16
24
|
* Error is thrown when the device can't connect to OkHi's servers.
|
|
17
25
|
*/
|
|
@@ -91,6 +99,10 @@ class OkHiException extends Error {
|
|
|
91
99
|
|
|
92
100
|
exports.OkHiException = OkHiException;
|
|
93
101
|
|
|
102
|
+
_defineProperty(OkHiException, "LOCATION_SERVICES_UNAVAILABLE_CODE", 'location_services_unavailable');
|
|
103
|
+
|
|
104
|
+
_defineProperty(OkHiException, "PLAY_SERVICES_UNAVAILABLE_CODE", 'play_services_unavailable');
|
|
105
|
+
|
|
94
106
|
_defineProperty(OkHiException, "NETWORK_ERROR_CODE", 'network_error');
|
|
95
107
|
|
|
96
108
|
_defineProperty(OkHiException, "NETWORK_ERROR_MESSAGE", 'Unable to establish a connection with OkHi servers');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["OkHiException.ts"],"names":["OkHiException","Error","constructor","error","message","name","code"],"mappings":";;;;;;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,aAAN,SAA4BC,KAA5B,CAAkC;AACvC;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAGE;AACF;AACA;AACA;AACA;AACEC,EAAAA,WAAW,CAACC,KAAD,EAAmB;AAC5B,UAAMA,KAAK,CAACC,OAAZ;;AAD4B;;AAE5B,SAAKC,IAAL,GAAY,eAAZ;AACA,SAAKD,OAAL,GAAeD,KAAK,CAACC,OAArB;AACA,SAAKE,IAAL,GAAYH,KAAK,CAACG,IAAlB;AACD;;
|
|
1
|
+
{"version":3,"sources":["OkHiException.ts"],"names":["OkHiException","Error","constructor","error","message","name","code"],"mappings":";;;;;;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,aAAN,SAA4BC,KAA5B,CAAkC;AACvC;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAEE;AACF;AACA;;AAGE;AACF;AACA;;AAGE;AACF;AACA;AACA;AACA;AACEC,EAAAA,WAAW,CAACC,KAAD,EAAmB;AAC5B,UAAMA,KAAK,CAACC,OAAZ;;AAD4B;;AAE5B,SAAKC,IAAL,GAAY,eAAZ;AACA,SAAKD,OAAL,GAAeD,KAAK,CAACC,OAArB;AACA,SAAKE,IAAL,GAAYH,KAAK,CAACG,IAAlB;AACD;;AArFsC;;;;gBAA5BN,a,wCAIiC,+B;;gBAJjCA,a,oCAS6B,2B;;gBAT7BA,a,wBAaiB,e;;gBAbjBA,a,2BAkBT,oD;;gBAlBSA,a,wBAsBiB,e;;gBAtBjBA,a,2BA2BT,qD;;gBA3BSA,a,wBA+BiB,e;;gBA/BjBA,a,2BAoCT,+E;;gBApCSA,a,uBAwCgB,c;;gBAxChBA,a,0BA4CmB,8B;;gBA5CnBA,a,4BAgDqB,mB;;gBAhDrBA,a,8BAoDuB,qB;;gBApDvBA,a,+BAwDwB,sB;;gBAxDxBA,a,kCA4D2B,mC;;gBA5D3BA,a,sBAgEe,a;;gBAhEfA,a,yBAoEkB,6B","sourcesContent":["import type { OkHiError } from './types';\n\n/**\n * The OkHiException class extends the Error class to provide additional information regarding the type of errors thrown while running any OkHiLibraries.\n * It contains static string properties that can be used to evaluate the kind of errors being thrown and handle them appropriately.\n */\nexport class OkHiException extends Error {\n /**\n * Error is thrown when location services is unavailable.\n */\n static LOCATION_SERVICES_UNAVAILABLE_CODE = 'location_services_unavailable';\n\n /**\n * Error is thrown when play services is unavailable.\n */\n static PLAY_SERVICES_UNAVAILABLE_CODE = 'play_services_unavailable';\n /**\n * Error is thrown when the device can't connect to OkHi's servers.\n */\n static NETWORK_ERROR_CODE = 'network_error';\n /**\n * Error is thrown when the device can't connect to OkHi's servers.\n */\n static NETWORK_ERROR_MESSAGE =\n 'Unable to establish a connection with OkHi servers';\n /**\n * Error is thrown whenever there's an unknown error that occured during the usage of one of OkHi's services.\n */\n static UNKNOWN_ERROR_CODE = 'unknown_error';\n /**\n * Error is thrown whenever there's an unknown error that occured during the usage of one of OkHi's services.\n */\n static UNKNOWN_ERROR_MESSAGE =\n 'Unable to process the request. Something went wrong';\n /**\n * Error is thrown whenever an invalid phone number is provided to a service that requires a user's phone number.\n */\n static INVALID_PHONE_CODE = 'invalid_phone';\n /**\n * Error is thrown whenever an invalid phone number is provided to a service that requires a user's phone number.\n */\n static INVALID_PHONE_MESSAGE =\n 'Invalid phone number provided. Please make sure its in MSISDN standard format';\n /**\n * Error is thrown whenever there's an issue with the credentials provided.\n */\n static UNAUTHORIZED_CODE = 'unauthorized';\n /**\n * Error is thrown whenever there's an issue with the credentials provided.\n */\n static UNAUTHORIZED_MESSAGE = 'Invalid credentials provided';\n /**\n * Error is thrown whenever a particular permission is required for a service to run and isn't granted by the user.\n */\n static PERMISSION_DENIED_CODE = 'permission_denied';\n /**\n * Error is thrown whenever a particular device service is required for a library to run and isn't granted by the user.\n */\n static SERVICE_UNAVAILABLE_CODE = 'service_unavailable';\n /**\n * Error is thrown whenever an OkHi service is run on an unsupported platform.\n */\n static UNSUPPORTED_PLATFORM_CODE = 'unsupported_platform';\n /**\n * Error is thrown whenever an OkHi service is run on an unsupported platform.\n */\n static UNSUPPORTED_PLATFORM_MESSAGE = 'Current platform is not supported';\n /**\n * Error is thrown whenever bad configuration is provided to an OkHi service.\n */\n static BAD_REQUEST_CODE = 'bad_request';\n /**\n * Error is thrown whenever bad configuration is provided to an OkHi service.\n */\n static BAD_REQUEST_MESSAGE = 'Invalid parameters provided';\n\n /**\n * Specific error code string detailing the kind of error being thrown.\n */\n code: string;\n\n /**\n * @param error An error object with code and respective message.\n * @param error.code Specific error code string detailing the kind of error being thrown.\n * @param error.message Specific error message string detailing the kind of error being thrown.\n */\n constructor(error: OkHiError) {\n super(error.message);\n this.name = 'OkHiException';\n this.message = error.message;\n this.code = error.code;\n }\n}\n"]}
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.OkHiNativeModule = void 0;
|
|
6
|
+
exports.OkHiNativeModule = exports.OkHiNativeEvents = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
10
|
const OkHiNativeModule = _reactNative.NativeModules.Okhi;
|
|
11
11
|
exports.OkHiNativeModule = OkHiNativeModule;
|
|
12
|
+
const OkHiNativeEvents = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.Okhi);
|
|
13
|
+
exports.OkHiNativeEvents = OkHiNativeEvents;
|
|
12
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["OkHiNativeModule","NativeModules","Okhi"],"mappings":";;;;;;;AAAA;;
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["OkHiNativeModule","NativeModules","Okhi","OkHiNativeEvents","NativeEventEmitter"],"mappings":";;;;;;;AAAA;;AAsCO,MAAMA,gBAAsC,GAAGC,2BAAcC,IAA7D;;AAEA,MAAMC,gBAAgB,GAAG,IAAIC,+BAAJ,CAAuBH,2BAAcC,IAArC,CAAzB","sourcesContent":["import { NativeModules, NativeEventEmitter } from 'react-native';\nimport type { OkVerifyStartConfiguration } from '../OkVerify/types';\n\ntype OkHiNativeModuleType = {\n multiply(a: number, b: number): Promise<number>;\n isLocationServicesEnabled(): Promise<boolean>;\n isLocationPermissionGranted(): Promise<boolean>;\n isBackgroundLocationPermissionGranted(): Promise<boolean>;\n requestLocationPermission(): Promise<boolean>;\n requestBackgroundLocationPermission(): Promise<boolean>;\n requestEnableLocationServices(): Promise<boolean>;\n isGooglePlayServicesAvailable(): Promise<boolean>;\n requestEnableGooglePlayServices(): Promise<boolean>;\n getSystemVersion(): Promise<number | string>;\n getAuthToken(branchId: string, clientKey: string): Promise<string>;\n initialize(configuration: string): Promise<void>;\n startAddressVerification(\n phoneNumber: string,\n locationId: string,\n lat: Number,\n lon: Number,\n configuration?: OkVerifyStartConfiguration\n ): Promise<string>;\n stopAddressVerification(\n phoneNumber: string,\n locationId: string\n ): Promise<string>;\n startForegroundService(): Promise<boolean>;\n stopForegroundService(): Promise<boolean>;\n isForegroundServiceRunning(): Promise<boolean>;\n initializeIOS(\n branchId: string,\n clientKey: string,\n environment: string\n ): Promise<boolean>;\n openAppSettings(): Promise<void>;\n};\n\nexport const OkHiNativeModule: OkHiNativeModuleType = NativeModules.Okhi;\n\nexport const OkHiNativeEvents = new NativeEventEmitter(NativeModules.Okhi);\n"]}
|
|
@@ -10,9 +10,10 @@ var _exportNames = {
|
|
|
10
10
|
startForegroundService: true,
|
|
11
11
|
stopForegroundService: true,
|
|
12
12
|
isForegroundServiceRunning: true,
|
|
13
|
-
canStartVerification: true
|
|
13
|
+
canStartVerification: true,
|
|
14
|
+
checkVerificationStartRequirements: true
|
|
14
15
|
};
|
|
15
|
-
exports.stopVerification = exports.stopForegroundService = exports.startVerification = exports.startForegroundService = exports.start = exports.isForegroundServiceRunning = exports.canStartVerification = void 0;
|
|
16
|
+
exports.stopVerification = exports.stopForegroundService = exports.startVerification = exports.startForegroundService = exports.start = exports.isForegroundServiceRunning = exports.checkVerificationStartRequirements = exports.canStartVerification = void 0;
|
|
16
17
|
|
|
17
18
|
var _reactNative = require("react-native");
|
|
18
19
|
|
|
@@ -157,32 +158,89 @@ const canStartVerification = configuration => {
|
|
|
157
158
|
const locationServicesStatus = await (0, _Helpers.isLocationServicesEnabled)();
|
|
158
159
|
const googlePlayServices = _reactNative.Platform.OS === 'android' ? await (0, _Helpers.isGooglePlayServicesAvailable)() : true;
|
|
159
160
|
const backgroundLocationPerm = await (0, _Helpers.isBackgroundLocationPermissionGranted)();
|
|
161
|
+
const whenInUseLocationPerm = await (0, _Helpers.isLocationPermissionGranted)();
|
|
160
162
|
|
|
161
163
|
if (!requestServices) {
|
|
162
164
|
resolve(locationServicesStatus && googlePlayServices && backgroundLocationPerm);
|
|
163
165
|
return;
|
|
164
166
|
}
|
|
165
167
|
|
|
166
|
-
if (
|
|
168
|
+
if (_reactNative.Platform.OS === 'ios') {
|
|
169
|
+
if (!locationServicesStatus) {
|
|
170
|
+
reject(new _OkHiException.OkHiException({
|
|
171
|
+
code: _OkHiException.OkHiException.SERVICE_UNAVAILABLE_CODE,
|
|
172
|
+
message: 'Location services is unavailable'
|
|
173
|
+
}));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (backgroundLocationPerm) {
|
|
178
|
+
resolve(true);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (whenInUseLocationPerm && !backgroundLocationPerm) {
|
|
183
|
+
resolve(false);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const iosPerm = await (0, _Helpers.requestBackgroundLocationPermission)();
|
|
188
|
+
resolve(iosPerm);
|
|
189
|
+
return;
|
|
190
|
+
} else if (_reactNative.Platform.OS === 'android') {
|
|
191
|
+
const locationServicesRequestStatus = await (0, _Helpers.requestEnableLocationServices)();
|
|
192
|
+
const gPlayServices = await (0, _Helpers.requestEnableGooglePlayServices)();
|
|
193
|
+
const androidPerm = (await (0, _Helpers.requestLocationPermission)()) && (await (0, _Helpers.requestBackgroundLocationPermission)());
|
|
194
|
+
resolve(locationServicesRequestStatus && gPlayServices && androidPerm);
|
|
195
|
+
} else {
|
|
167
196
|
reject(new _OkHiException.OkHiException({
|
|
168
|
-
code: _OkHiException.OkHiException.
|
|
169
|
-
message:
|
|
197
|
+
code: _OkHiException.OkHiException.UNSUPPORTED_PLATFORM_CODE,
|
|
198
|
+
message: _OkHiException.OkHiException.UNSUPPORTED_PLATFORM_MESSAGE
|
|
170
199
|
}));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Checks whether all necessary permissions and services are available in order to start the address verification process
|
|
205
|
+
* @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
|
|
206
|
+
*/
|
|
175
207
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
208
|
+
|
|
209
|
+
exports.canStartVerification = canStartVerification;
|
|
210
|
+
|
|
211
|
+
const checkVerificationStartRequirements = () => {
|
|
212
|
+
return new Promise(async (resolve, reject) => {
|
|
213
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
214
|
+
const isPlayServicesAvailable = await (0, _Helpers.isGooglePlayServicesAvailable)();
|
|
215
|
+
|
|
216
|
+
if (!isPlayServicesAvailable) {
|
|
217
|
+
reject(new _OkHiException.OkHiException({
|
|
218
|
+
code: _OkHiException.OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,
|
|
219
|
+
message: 'Google Play Services is unavailable'
|
|
220
|
+
}));
|
|
221
|
+
return;
|
|
180
222
|
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!(await (0, _Helpers.isLocationServicesEnabled)())) {
|
|
226
|
+
reject(new _OkHiException.OkHiException({
|
|
227
|
+
code: _OkHiException.OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,
|
|
228
|
+
message: 'Location services unavailable'
|
|
229
|
+
}));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
181
232
|
|
|
182
|
-
|
|
233
|
+
if (!(await (0, _Helpers.isBackgroundLocationPermissionGranted)())) {
|
|
234
|
+
reject(new _OkHiException.OkHiException({
|
|
235
|
+
code: _OkHiException.OkHiException.PERMISSION_DENIED_CODE,
|
|
236
|
+
message: 'Background Location permission not granted'
|
|
237
|
+
}));
|
|
238
|
+
return;
|
|
183
239
|
}
|
|
240
|
+
|
|
241
|
+
resolve(true);
|
|
184
242
|
});
|
|
185
243
|
};
|
|
186
244
|
|
|
187
|
-
exports.
|
|
245
|
+
exports.checkVerificationStartRequirements = checkVerificationStartRequirements;
|
|
188
246
|
//# sourceMappingURL=index.js.map
|
|
@@ -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","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,CAC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d;AAIA,YAAM6B,aAAa,GACjB9B,sBAASC,EAAT,KAAgB,KAAhB,GAAwB,IAAxB,GAA+B,MAAM,+CADvC;AAEA,UAAI8B,IAAI,GAAG,KAAX;;AACA,UAAI/B,sBAASC,EAAT,KAAgB,KAApB,EAA2B;AACzB8B,QAAAA,IAAI,GAAG,MAAM,mDAAb;AACD,OAFD,MAEO;AACLA,QAAAA,IAAI,GACF,CAAC,MAAM,yCAAP,MACC,MAAM,mDADP,CADF;AAGD;;AACDxB,MAAAA,OAAO,CAACsB,6BAA6B,IAAIC,aAAjC,IAAkDC,IAAnD,CAAP;AACD;AACF,GArCM,CAAP;AAsCD,CAzCM","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 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"]}
|
|
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","whenInUseLocationPerm","SERVICE_UNAVAILABLE_CODE","iosPerm","locationServicesRequestStatus","gPlayServices","androidPerm","UNSUPPORTED_PLATFORM_CODE","UNSUPPORTED_PLATFORM_MESSAGE","checkVerificationStartRequirements","isPlayServicesAvailable","PLAY_SERVICES_UNAVAILABLE_CODE","LOCATION_SERVICES_UNAVAILABLE_CODE","PERMISSION_DENIED_CODE"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AAUA;;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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\nimport {\n isBackgroundLocationPermissionGranted,\n isGooglePlayServicesAvailable,\n isLocationServicesEnabled,\n requestBackgroundLocationPermission,\n requestEnableGooglePlayServices,\n requestEnableLocationServices,\n requestLocationPermission,\n isLocationPermissionGranted,\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 const whenInUseLocationPerm = await isLocationPermissionGranted();\n if (!requestServices) {\n resolve(\n locationServicesStatus && googlePlayServices && backgroundLocationPerm\n );\n return;\n }\n if (Platform.OS === 'ios') {\n if (!locationServicesStatus) {\n reject(\n new OkHiException({\n code: OkHiException.SERVICE_UNAVAILABLE_CODE,\n message: 'Location services is unavailable',\n })\n );\n return;\n }\n if (backgroundLocationPerm) {\n resolve(true);\n return;\n }\n if (whenInUseLocationPerm && !backgroundLocationPerm) {\n resolve(false);\n return;\n }\n const iosPerm = await requestBackgroundLocationPermission();\n resolve(iosPerm);\n return;\n } else if (Platform.OS === 'android') {\n const locationServicesRequestStatus =\n (await requestEnableLocationServices()) as boolean;\n const gPlayServices = await requestEnableGooglePlayServices();\n const androidPerm =\n (await requestLocationPermission()) &&\n (await requestBackgroundLocationPermission());\n resolve(locationServicesRequestStatus && gPlayServices && androidPerm);\n } else {\n reject(\n new OkHiException({\n code: OkHiException.UNSUPPORTED_PLATFORM_CODE,\n message: OkHiException.UNSUPPORTED_PLATFORM_MESSAGE,\n })\n );\n }\n });\n};\n\n/**\n * Checks whether all necessary permissions and services are available in order to start the address verification process\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 checkVerificationStartRequirements = (): Promise<boolean> => {\n return new Promise(async (resolve, reject) => {\n if (Platform.OS === 'android') {\n const isPlayServicesAvailable = await isGooglePlayServicesAvailable();\n if (!isPlayServicesAvailable) {\n reject(\n new OkHiException({\n code: OkHiException.PLAY_SERVICES_UNAVAILABLE_CODE,\n message: 'Google Play Services is unavailable',\n })\n );\n return;\n }\n }\n if (!(await isLocationServicesEnabled())) {\n reject(\n new OkHiException({\n code: OkHiException.LOCATION_SERVICES_UNAVAILABLE_CODE,\n message: 'Location services unavailable',\n })\n );\n return;\n }\n if (!(await isBackgroundLocationPermissionGranted())) {\n reject(\n new OkHiException({\n code: OkHiException.PERMISSION_DENIED_CODE,\n message: 'Background Location permission not granted',\n })\n );\n return;\n }\n resolve(true);\n });\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OkHiNativeModule } from '../OkHiNativeModule';
|
|
2
|
-
import { PermissionsAndroid, Platform } from 'react-native';
|
|
1
|
+
import { OkHiNativeModule, OkHiNativeEvents } from '../OkHiNativeModule';
|
|
2
|
+
import { Alert, PermissionsAndroid, Platform } from 'react-native';
|
|
3
3
|
import { errorHandler, isValidPlatform } from './_helpers';
|
|
4
4
|
/**
|
|
5
5
|
* Checks whether location services are enabled
|
|
@@ -62,6 +62,7 @@ const requestLocationPermissionIOS = () => {
|
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
export const requestLocationPermission = async () => {
|
|
65
|
+
console.log('yooo');
|
|
65
66
|
const isGranted = await isLocationPermissionGranted();
|
|
66
67
|
if (isGranted) return isGranted;
|
|
67
68
|
return errorHandler(Platform.OS === 'android' ? requestLocationPermissionAndroid : requestLocationPermissionIOS);
|
|
@@ -124,4 +125,48 @@ export const requestEnableGooglePlayServices = () => {
|
|
|
124
125
|
*/
|
|
125
126
|
|
|
126
127
|
export const getSystemVersion = () => isValidPlatform(OkHiNativeModule.getSystemVersion);
|
|
128
|
+
export const request = (locationPermissionType, rationale, callback) => {
|
|
129
|
+
if (Platform.OS === 'ios') {
|
|
130
|
+
OkHiNativeEvents.removeAllListeners('onLocationPermissionStatusUpdate');
|
|
131
|
+
OkHiNativeEvents.addListener('onLocationPermissionStatusUpdate', callback);
|
|
132
|
+
|
|
133
|
+
if (locationPermissionType === 'whenInUse') {
|
|
134
|
+
OkHiNativeModule.requestLocationPermission();
|
|
135
|
+
} else {
|
|
136
|
+
OkHiNativeModule.requestBackgroundLocationPermission();
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
if (locationPermissionType === 'whenInUse') {
|
|
140
|
+
requestLocationPermissionAndroid().then(result => callback(result ? 'authorizedWhenInUse' : 'denied'));
|
|
141
|
+
} else {
|
|
142
|
+
requestLocationPermissionAndroid().then(async whenInUseResult => {
|
|
143
|
+
if (whenInUseResult) {
|
|
144
|
+
const version = await getSystemVersion();
|
|
145
|
+
|
|
146
|
+
if (version >= 30 && rationale) {
|
|
147
|
+
Alert.alert(rationale.title, rationale.text, [{
|
|
148
|
+
text: rationale.successButton ? rationale.successButton.label : 'Okay',
|
|
149
|
+
onPress: async () => {
|
|
150
|
+
const result = await requestBackgroundLocationPermission();
|
|
151
|
+
callback(result ? 'authorizedAlways' : 'authorizedWhenInUse');
|
|
152
|
+
}
|
|
153
|
+
}], {
|
|
154
|
+
onDismiss: () => {
|
|
155
|
+
callback('authorizedWhenInUse');
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
const permission = await requestBackgroundLocationPermission();
|
|
160
|
+
callback(permission ? 'authorizedAlways' : 'authorizedWhenInUse');
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
callback('denied');
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
export const openAppSettings = () => {
|
|
170
|
+
OkHiNativeModule.openAppSettings();
|
|
171
|
+
};
|
|
127
172
|
//# sourceMappingURL=Helpers.js.map
|