|
@@ -5,7 +5,8 @@ const PermissionsIOS = NativeModules.ReactNativePermissions
|
5
|
5
|
|
6
|
6
|
type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
|
7
|
7
|
type Rationale = { title: string, message: string }
|
8
|
|
-type Options = string | { type: string, rationale?: Rationale }
|
|
8
|
+type CheckOptions = string | { type: string }
|
|
9
|
+type RequestOptions = string | { type: string, rationale?: Rationale }
|
9
|
10
|
|
10
|
11
|
const permissionTypes = [
|
11
|
12
|
'location',
|
|
@@ -34,7 +35,7 @@ class ReactNativePermissions {
|
34
|
35
|
|
35
|
36
|
getTypes: () => Array<string> = () => permissionTypes
|
36
|
37
|
|
37
|
|
- check = (permission: string, type?: string): Promise<Status> => {
|
|
38
|
+ check = (permission: string, options?: CheckOptions): Promise<Status> => {
|
38
|
39
|
if (!permissionTypes.includes(permission)) {
|
39
|
40
|
const error = new Error(
|
40
|
41
|
`ReactNativePermissions: ${
|
|
@@ -45,13 +46,6 @@ class ReactNativePermissions {
|
45
|
46
|
return Promise.reject(error)
|
46
|
47
|
}
|
47
|
48
|
|
48
|
|
- return PermissionsIOS.getPermissionStatus(
|
49
|
|
- permission,
|
50
|
|
- type || DEFAULTS[permission],
|
51
|
|
- )
|
52
|
|
- }
|
53
|
|
-
|
54
|
|
- request = (permission: string, options?: Options): Promise<Status> => {
|
55
|
49
|
let type
|
56
|
50
|
|
57
|
51
|
if (typeof options === 'string') {
|
|
@@ -60,6 +54,13 @@ class ReactNativePermissions {
|
60
|
54
|
type = options.type
|
61
|
55
|
}
|
62
|
56
|
|
|
57
|
+ return PermissionsIOS.getPermissionStatus(
|
|
58
|
+ permission,
|
|
59
|
+ type || DEFAULTS[permission],
|
|
60
|
+ )
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ request = (permission: string, options?: RequestOptions): Promise<Status> => {
|
63
|
64
|
if (!permissionTypes.includes(permission)) {
|
64
|
65
|
const error = new Error(
|
65
|
66
|
`ReactNativePermissions: ${
|
|
@@ -78,6 +79,14 @@ class ReactNativePermissions {
|
78
|
79
|
return Promise.reject(error)
|
79
|
80
|
}
|
80
|
81
|
|
|
82
|
+ let type
|
|
83
|
+
|
|
84
|
+ if (typeof options === 'string') {
|
|
85
|
+ type = options
|
|
86
|
+ } else if (options && options.type) {
|
|
87
|
+ type = options.type
|
|
88
|
+ }
|
|
89
|
+
|
81
|
90
|
return PermissionsIOS.requestPermission(
|
82
|
91
|
permission,
|
83
|
92
|
type || DEFAULTS[permission],
|