Skip to content

Commit d484730

Browse files
authored
Add authorizationStatus in permissions object (#185)
1 parent c322633 commit d484730

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ See what push permissions are currently enabled.
469469
- `sound` :boolean
470470
- `lockScreen` :boolean
471471
- `notificationCenter` :boolean
472+
- `authorizationStatus` :AuthorizationStatus
472473

474+
For a list of possible values of `authorizationStatus`, see `PushNotificationIOS.AuthorizationStatus`. For their meanings, refer to https://developer.apple.com/documentation/usernotifications/unauthorizationstatus
473475
---
474476

475477
### `getInitialNotification()`

index.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ export interface FetchResult {
88
ResultFailed: 'UIBackgroundFetchResultFailed';
99
}
1010

11+
export interface AuthorizationStatus {
12+
UNAuthorizationStatusNotDetermined: 0;
13+
UNAuthorizationStatusDenied: 1;
14+
UNAuthorizationStatusAuthorized: 2;
15+
UNAuthorizationStatusProvisional: 3;
16+
}
17+
1118
export interface PushNotification {
1219
/**
1320
* An alias for `getAlert` to get the notification's main message string
@@ -148,6 +155,9 @@ export interface PushNotificationPermissions {
148155
alert?: boolean;
149156
badge?: boolean;
150157
sound?: boolean;
158+
lockScreen?: boolean;
159+
notificationCenter?: boolean;
160+
authorizationStatus?: AuthorizationStatus;
151161
}
152162

153163
export type PushNotificationEventName =
@@ -168,6 +178,11 @@ export interface PushNotificationIOSStatic {
168178
* For a list of possible values, see `PushNotificationIOS.FetchResult`.
169179
*/
170180
FetchResult: FetchResult;
181+
/**
182+
* Authorization status of notification settings
183+
* For a list of possible values, see `PushNotificationIOS.AuthorizationStatus`.
184+
*/
185+
AuthorizationStatus: AuthorizationStatus;
171186
/**
172187
* Schedules the localNotification for immediate presentation.
173188
* details is an object containing:

ios/RNCPushNotificationIOS.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
356356
RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback)
357357
{
358358
if (RCTRunningInAppExtension()) {
359-
callback(@[RCTSettingsDictForUNNotificationSettings(NO, NO, NO, NO, NO)]);
359+
callback(@[RCTSettingsDictForUNNotificationSettings(NO, NO, NO, NO, NO, UNAuthorizationStatusNotDetermined)]);
360360
return;
361361
}
362362

@@ -370,11 +370,12 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
370370
settings.badgeSetting == UNNotificationSettingEnabled,
371371
settings.soundSetting == UNNotificationSettingEnabled,
372372
settings.lockScreenSetting == UNNotificationSettingEnabled,
373-
settings.notificationCenterSetting == UNNotificationSettingEnabled);
373+
settings.notificationCenterSetting == UNNotificationSettingEnabled,
374+
settings.authorizationStatus);
374375
}
375376

376-
static inline NSDictionary *RCTSettingsDictForUNNotificationSettings(BOOL alert, BOOL badge, BOOL sound, BOOL lockScreen, BOOL notificationCenter) {
377-
return @{@"alert": @(alert), @"badge": @(badge), @"sound": @(sound), @"lockScreen": @(lockScreen), @"notificationCenter": @(notificationCenter)};
377+
static inline NSDictionary *RCTSettingsDictForUNNotificationSettings(BOOL alert, BOOL badge, BOOL sound, BOOL lockScreen, BOOL notificationCenter, UNAuthorizationStatus authorizationStatus) {
378+
return @{@"alert": @(alert), @"badge": @(badge), @"sound": @(sound), @"lockScreen": @(lockScreen), @"notificationCenter": @(notificationCenter), @"authorizationStatus": @(authorizationStatus)};
378379
}
379380

380381

js/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ export type FetchResult = {
3232
ResultFailed: string,
3333
};
3434

35+
export type AuthorizationStatus = {
36+
UNAuthorizationStatusNotDetermined: 0,
37+
UNAuthorizationStatusDenied: 1,
38+
UNAuthorizationStatusAuthorized: 2,
39+
UNAuthorizationStatusProvisional: 3,
40+
};
41+
3542
/**
3643
* An event emitted by PushNotificationIOS.
3744
*/
@@ -86,6 +93,13 @@ class PushNotificationIOS {
8693
ResultFailed: 'UIBackgroundFetchResultFailed',
8794
};
8895

96+
static AuthorizationStatus: AuthorizationStatus = {
97+
UNAuthorizationStatusNotDetermined: 0,
98+
UNAuthorizationStatusDenied: 1,
99+
UNAuthorizationStatusAuthorized: 2,
100+
UNAuthorizationStatusProvisional: 3,
101+
};
102+
89103
/**
90104
* Schedules the localNotification for immediate presentation.
91105
*

0 commit comments

Comments
 (0)