Skip to content

Add authorizationStatus in permissions object #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down
15 changes: 15 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -148,6 +155,9 @@ export interface PushNotificationPermissions {
alert?: boolean;
badge?: boolean;
sound?: boolean;
lockScreen?: boolean;
notificationCenter?: boolean;
authorizationStatus?: AuthorizationStatus;
}

export type PushNotificationEventName =
Expand All @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions ios/RNCPushNotificationIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)};
}


Expand Down
14 changes: 14 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export type FetchResult = {
ResultFailed: string,
};

export type AuthorizationStatus = {
UNAuthorizationStatusNotDetermined: 0,
UNAuthorizationStatusDenied: 1,
UNAuthorizationStatusAuthorized: 2,
UNAuthorizationStatusProvisional: 3,
};

/**
* An event emitted by PushNotificationIOS.
*/
Expand Down Expand Up @@ -86,6 +93,13 @@ class PushNotificationIOS {
ResultFailed: 'UIBackgroundFetchResultFailed',
};

static AuthorizationStatus: AuthorizationStatus = {
UNAuthorizationStatusNotDetermined: 0,
UNAuthorizationStatusDenied: 1,
UNAuthorizationStatusAuthorized: 2,
UNAuthorizationStatusProvisional: 3,
};

/**
* Schedules the localNotification for immediate presentation.
*
Expand Down