|
|
@@ -5,7 +5,8 @@ const PermissionsIOS = NativeModules.ReactNativePermissions
|
|
|
|
|
|
type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
|
|
|
type Rationale = { title: string, message: string }
|
|
|
-type Options = string | { type: string, rationale?: Rationale }
|
|
|
+type CheckOptions = string | { type: string }
|
|
|
+type RequestOptions = string | { type: string, rationale?: Rationale }
|
|
|
|
|
|
const permissionTypes = [
|
|
|
'location',
|
|
|
@@ -34,7 +35,7 @@ class ReactNativePermissions {
|
|
|
|
|
|
getTypes: () => Array<string> = () => permissionTypes
|
|
|
|
|
|
- check = (permission: string, type?: string): Promise<Status> => {
|
|
|
+ check = (permission: string, options?: CheckOptions): Promise<Status> => {
|
|
|
if (!permissionTypes.includes(permission)) {
|
|
|
const error = new Error(
|
|
|
`ReactNativePermissions: ${
|
|
|
@@ -45,13 +46,6 @@ class ReactNativePermissions {
|
|
|
return Promise.reject(error)
|
|
|
}
|
|
|
|
|
|
- return PermissionsIOS.getPermissionStatus(
|
|
|
- permission,
|
|
|
- type || DEFAULTS[permission],
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- request = (permission: string, options?: Options): Promise<Status> => {
|
|
|
let type
|
|
|
|
|
|
if (typeof options === 'string') {
|
|
|
@@ -60,6 +54,13 @@ class ReactNativePermissions {
|
|
|
type = options.type
|
|
|
}
|
|
|
|
|
|
+ return PermissionsIOS.getPermissionStatus(
|
|
|
+ permission,
|
|
|
+ type || DEFAULTS[permission],
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ request = (permission: string, options?: RequestOptions): Promise<Status> => {
|
|
|
if (!permissionTypes.includes(permission)) {
|
|
|
const error = new Error(
|
|
|
`ReactNativePermissions: ${
|
|
|
@@ -78,6 +79,14 @@ class ReactNativePermissions {
|
|
|
return Promise.reject(error)
|
|
|
}
|
|
|
|
|
|
+ let type
|
|
|
+
|
|
|
+ if (typeof options === 'string') {
|
|
|
+ type = options
|
|
|
+ } else if (options && options.type) {
|
|
|
+ type = options.type
|
|
|
+ }
|
|
|
+
|
|
|
return PermissionsIOS.requestPermission(
|
|
|
permission,
|
|
|
type || DEFAULTS[permission],
|