From e315f10f39858387c1c4920835ea0ab324458621 Mon Sep 17 00:00:00 2001 From: Maxi Cho Date: Thu, 24 Sep 2020 16:35:55 +0800 Subject: [PATCH 1/3] feat: add authorizationStatus in the permissions object --- index.d.ts | 15 +++++++++++++++ ios/RNCPushNotificationIOS.m | 9 +++++---- js/index.js | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index ddfacbfee..0f8792663 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,6 +8,13 @@ export interface FetchResult { ResultFailed: 'UIBackgroundFetchResultFailed'; } +export interface AuthorizationStatus { + UNAuthorizationStatusNotDetermined: 0; + UNAuthorizationStatusDenied: 1; + UNAuthorizationStatusAuthorized: 2; + UNAuthorizationStatusProvisional: 3; +} + export interface PushNotification { /** * An alias for `getAlert` to get the notification's main message string @@ -148,6 +155,9 @@ export interface PushNotificationPermissions { alert?: boolean; badge?: boolean; sound?: boolean; + lockScreen?: boolean; + notificationCenter?: boolean; + authorizationStatus?: AuthorizationStatus; } export type PushNotificationEventName = @@ -168,6 +178,11 @@ export interface PushNotificationIOSStatic { * For a list of possible values, see `PushNotificationIOS.FetchResult`. */ FetchResult: FetchResult; + /** + * Authorization status of notification settings + * For a list of possible values, see `PushNotificationIOS.AuthorizationStatus`. + */ + AuthorizationStatus: AuthorizationStatus; /** * Schedules the localNotification for immediate presentation. * details is an object containing: diff --git a/ios/RNCPushNotificationIOS.m b/ios/RNCPushNotificationIOS.m index 1b9630f07..2bc524eb5 100644 --- a/ios/RNCPushNotificationIOS.m +++ b/ios/RNCPushNotificationIOS.m @@ -356,7 +356,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback) { if (RCTRunningInAppExtension()) { - callback(@[RCTSettingsDictForUNNotificationSettings(NO, NO, NO, NO, NO)]); + callback(@[RCTSettingsDictForUNNotificationSettings(NO, NO, NO, NO, NO, UNAuthorizationStatusNotDetermined)]); return; } @@ -370,11 +370,12 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification settings.badgeSetting == UNNotificationSettingEnabled, settings.soundSetting == UNNotificationSettingEnabled, settings.lockScreenSetting == UNNotificationSettingEnabled, - settings.notificationCenterSetting == UNNotificationSettingEnabled); + settings.notificationCenterSetting == UNNotificationSettingEnabled, + settings.authorizationStatus); } -static inline NSDictionary *RCTSettingsDictForUNNotificationSettings(BOOL alert, BOOL badge, BOOL sound, BOOL lockScreen, BOOL notificationCenter) { - return @{@"alert": @(alert), @"badge": @(badge), @"sound": @(sound), @"lockScreen": @(lockScreen), @"notificationCenter": @(notificationCenter)}; +static inline NSDictionary *RCTSettingsDictForUNNotificationSettings(BOOL alert, BOOL badge, BOOL sound, BOOL lockScreen, BOOL notificationCenter, UNAuthorizationStatus authorizationStatus) { + return @{@"alert": @(alert), @"badge": @(badge), @"sound": @(sound), @"lockScreen": @(lockScreen), @"notificationCenter": @(notificationCenter), @"authorizationStatus": @(authorizationStatus)}; } diff --git a/js/index.js b/js/index.js index e556d3587..38e632ee7 100644 --- a/js/index.js +++ b/js/index.js @@ -32,6 +32,13 @@ export type FetchResult = { ResultFailed: string, }; +export type AuthorizationStatus = { + UNAuthorizationStatusNotDetermined: Number; + UNAuthorizationStatusDenied: Number; + UNAuthorizationStatusAuthorized: Number; + UNAuthorizationStatusProvisional: Number; +} + /** * An event emitted by PushNotificationIOS. */ @@ -85,6 +92,13 @@ class PushNotificationIOS { NoData: 'UIBackgroundFetchResultNoData', ResultFailed: 'UIBackgroundFetchResultFailed', }; + + static AuthorizationStatus: AuthorizationStatus = { + UNAuthorizationStatusNotDetermined: 0, + UNAuthorizationStatusDenied: 1, + UNAuthorizationStatusAuthorized: 2, + UNAuthorizationStatusProvisional: 3, + }; /** * Schedules the localNotification for immediate presentation. From d42d37a5bdd68876593e19f05a7d7e48c0ac3129 Mon Sep 17 00:00:00 2001 From: Maxi Cho Date: Thu, 24 Sep 2020 16:41:55 +0800 Subject: [PATCH 2/3] docs: update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7eaee9d7b..cfdab16ee 100644 --- a/README.md +++ b/README.md @@ -469,7 +469,9 @@ See what push permissions are currently enabled. - `sound` :boolean - `lockScreen` :boolean - `notificationCenter` :boolean +- `authorizationStatus` :AuthorizationStatus + For a list of possible values of `authorizationStatus`, see `PushNotificationIOS.AuthorizationStatus`. For their meanings, refer to https://developer.apple.com/documentation/usernotifications/unauthorizationstatus --- ### `getInitialNotification()` From f5e3e904dfd259a1a1a5bf8ca6b4bfaa67da9e26 Mon Sep 17 00:00:00 2001 From: Maxi Cho Date: Thu, 24 Sep 2020 17:04:35 +0800 Subject: [PATCH 3/3] fix: lint error and test:flow error --- js/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/index.js b/js/index.js index 38e632ee7..e7de8ed04 100644 --- a/js/index.js +++ b/js/index.js @@ -33,11 +33,11 @@ export type FetchResult = { }; export type AuthorizationStatus = { - UNAuthorizationStatusNotDetermined: Number; - UNAuthorizationStatusDenied: Number; - UNAuthorizationStatusAuthorized: Number; - UNAuthorizationStatusProvisional: Number; -} + UNAuthorizationStatusNotDetermined: 0, + UNAuthorizationStatusDenied: 1, + UNAuthorizationStatusAuthorized: 2, + UNAuthorizationStatusProvisional: 3, +}; /** * An event emitted by PushNotificationIOS. @@ -92,7 +92,7 @@ class PushNotificationIOS { NoData: 'UIBackgroundFetchResultNoData', ResultFailed: 'UIBackgroundFetchResultFailed', }; - + static AuthorizationStatus: AuthorizationStatus = { UNAuthorizationStatusNotDetermined: 0, UNAuthorizationStatusDenied: 1,