nativescript-community / perms

An unified permissions API for NativeScript on iOS and Android.
https://nativescript-community.github.io/perms/
Apache License 2.0
12 stars 9 forks source link

Android shouldShowRequestPermissionRationale() is needed for 33 #19

Closed sublime392 closed 1 year ago

sublime392 commented 1 year ago

Some of the permissions such as background location and notifications require checking shouldShowRequestPermissionRationale() to see if a message should be shown prior to requesting the permission https://developer.android.com/develop/ui/views/notifications/notification-permission#wait-to-show-prompt

Here is the patch I am using for this. It seems to work well enough, but I am not confident that it is solid/polished enough for a PR.

diff --git a/node_modules/@nativescript-community/perms/index.android.d.ts b/node_modules/@nativescript-community/perms/index.android.d.ts
index 482fcac..aca137b 100644
--- a/node_modules/@nativescript-community/perms/index.android.d.ts
+++ b/node_modules/@nativescript-community/perms/index.android.d.ts
@@ -1,6 +1,7 @@
 import { CheckOptions, MultiResult, ObjectPermissions, ObjectPermissionsRest, Permissions as PermissionsType, RequestOptions, Status } from '.';
 export * from './index.common';
 export declare function canOpenSettings(): Promise<boolean>;
+export declare function shouldShowRequestPermissionRationale(permission: PermissionsType | string): Promise<boolean>;
 export declare function openSettings(): Promise<void>;
 export declare function getTypes(): PermissionsType[];
 export declare function check(permission: PermissionsType | string, options?: CheckOptions): Promise<[Status, boolean]>;
diff --git a/node_modules/@nativescript-community/perms/index.android.js b/node_modules/@nativescript-community/perms/index.android.js
index 4c896bc..f6c14c7 100644
--- a/node_modules/@nativescript-community/perms/index.android.js
+++ b/node_modules/@nativescript-community/perms/index.android.js
@@ -306,7 +306,7 @@ async function requestMultiplePermissions(permissions) {
         }
     });
 }
-function shouldShowRequestPermissionRationale(permission) {
+export function shouldShowRequestPermissionRationale(permission) {
     if (getAndroidSDK() < MARSHMALLOW) {
         return Promise.resolve(false);
     }
diff --git a/node_modules/@nativescript-community/perms/index.d.ts b/node_modules/@nativescript-community/perms/index.d.ts
index 1d39e6d..1da94ac 100644
--- a/node_modules/@nativescript-community/perms/index.d.ts
+++ b/node_modules/@nativescript-community/perms/index.d.ts
@@ -77,3 +77,4 @@ export function request<T extends Partial<ObjectPermissions | ObjectPermissionsR
 export function request<T extends string>(permission: T): Promise<Result>;

 export function checkMultiple<T extends Partial<ObjectPermissionsRest>>(permissions: T): Promise<MultiResult>;
+export function shouldShowRequestPermissionRationale<T extends string>(permission: T): Promise<boolean>;
\ No newline at end of file
diff --git a/node_modules/@nativescript-community/perms/index.ios.d.ts b/node_modules/@nativescript-community/perms/index.ios.d.ts
index 2757bc2..0fa49bc 100644
--- a/node_modules/@nativescript-community/perms/index.ios.d.ts
+++ b/node_modules/@nativescript-community/perms/index.ios.d.ts
@@ -43,3 +43,4 @@ declare type Result<T> = T extends any[] ? MultipleResult : SingleResult;
 export declare function check(permission: IOSPermissionTypes, options?: CheckOptions): Promise<SingleResult>;
 export declare function request<T extends IOSPermissionTypes | Record<IOSPermissionTypes, any>>(permission: T, options?: RequestOptions): Promise<Result<T>>;
 export declare function checkMultiple<T extends Partial<ObjectIOSPermissionsRest>>(permissions: T): Promise<MultipleResult>;
+export declare function shouldShowRequestPermissionRationale(permission: IOSPermissionTypes | string): Promise<boolean>;
diff --git a/node_modules/@nativescript-community/perms/index.ios.js b/node_modules/@nativescript-community/perms/index.ios.js
index 44ae35b..f6bbbaf 100644
--- a/node_modules/@nativescript-community/perms/index.ios.js
+++ b/node_modules/@nativescript-community/perms/index.ios.js
@@ -796,4 +796,7 @@ export function checkMultiple(permissions) {
         return acc;
     }, {}));
 }
+export function shouldShowRequestPermissionRationale(permission) {
+  return Promise.resolve(false);
+}
 //# sourceMappingURL=index.ios.js.map
\ No newline at end of file
farfromrefug commented 1 year ago

@sublime392 can you please create a PR so I can see the changes more easily? Thanks

sublime392 commented 1 year ago

@farfromrefug done. fyi, In the published version (local node_modules) I also had to add the function declaration to the index.android.d.ts and index.ios.d.ts files, but those files do not seem to be present in the source repo.