Skip to content
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

Provisional option in iOS registeration #744

Merged
merged 1 commit into from
Jun 13, 2021
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
6 changes: 5 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ class NotificationsExampleApp extends Component {
return (
<View style={styles.container}>
<Button title={'Request permissions'} onPress={this.requestPermissions} testID={'requestPermissions'} />
{Platform.OS === 'ios' && <Button title={'Request permissions with app notification settings'} onPress={() => this.requestPermissionsIos(['ProvidesAppNotificationSettings'])} testID={'requestPermissionsWithAppSettings'} />}
{Platform.OS === 'ios' && Platform.Version > '12.0' && (<>
<Button title={'Request permissions with app notification settings'} onPress={() => this.requestPermissionsIos(['ProvidesAppNotificationSettings'])} testID={'requestPermissionsWithAppSettings'} />
<Button title={'Request permissions with provisional'} onPress={() => this.requestPermissionsIos(['Provisional'])} testID={'requestPermissionsWithAppSettings'} />
<Button title={'Request permissions with app notification settings and provisional'} onPress={() => this.requestPermissionsIos(['ProvidesAppNotificationSettings', 'Provisional'])} testID={'requestPermissionsWithAppSettings'} />
</>)}
<Button title={'Send local notification'} onPress={this.sendLocalNotification} testID={'sendLocalNotification'} />
<Button title={'Remove all delivered notifications'} onPress={this.removeAllDeliveredNotifications} />
{notifications}
Expand Down
9 changes: 8 additions & 1 deletion lib/ios/RNNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ - (void)requestPermissions:(NSArray *)options {
if ([options count] > 0) {
for (NSString* option in options) {
if ([option isEqualToString:@"ProvidesAppNotificationSettings"]) {
authOptions = (UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionProvidesAppNotificationSettings);
if (@available(iOS 12.0, *)) {
authOptions = authOptions | UNAuthorizationOptionProvidesAppNotificationSettings;
}
}
if ([option isEqualToString:@"Provisional"]) {
if (@available(iOS 12.0, *)) {
authOptions = authOptions | UNAuthorizationOptionProvisional;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ - (void)testRequestPermissions_withProvidesAppNotificationSettings {
[_notificationCenter verify];
}

- (void)testRequestPermissions_withProvisional {
UNAuthorizationOptions authOptions = (UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionProvisional);
UNNotificationSettings* settings = [UNNotificationSettings new];
[settings setValue:@(UNAuthorizationStatusAuthorized) forKey:@"authorizationStatus"];

[[_notificationCenter expect] requestAuthorizationWithOptions:authOptions completionHandler:[OCMArg invokeBlockWithArgs:@(YES), [NSNull null], nil]];
[[_notificationCenter expect] getNotificationSettingsWithCompletionHandler:[OCMArg invokeBlockWithArgs:settings, nil]];
[[(id)[UIApplication sharedApplication] expect] registerForRemoteNotifications];

[_uut requestPermissions:@[@"Provisional"]];
[_notificationCenter verify];
}

- (void)testRequestPermissions_userDeniedPermissions {
UNAuthorizationOptions authOptions = (UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert);
UNNotificationSettings* settings = [UNNotificationSettings new];
Expand Down
2 changes: 1 addition & 1 deletion lib/src/adapters/NativeCommandsSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface NativeCommandsModule {
finishHandlingBackgroundAction(notificationId: string, backgroundFetchResult: string): void;
}

export type RequestPermissionsOptions = 'ProvidesAppNotificationSettings';
export type RequestPermissionsOptions = 'ProvidesAppNotificationSettings' | 'Provisional';

export class NativeCommandsSender {
private readonly nativeCommandsModule: NativeCommandsModule;
Expand Down
12 changes: 10 additions & 2 deletions website/docs/api/ios-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ sidebar_label: iOS specific
---

## registerRemoteNotifications(options?: string[])
Requests notification permissions from iOS, prompting the user's dialog box.
Requests notification permissions from iOS, prompting the user's dialog box if needed.

Available options:
- **`ProvidesAppNotificationSettings`** - An option indicating the iOS notification settings to display a button for in-app notification settings and to be [informed in the app on this event](ios-events.md#appNotificationSettingsLinked).
- **`Provisional`** - Use provisional authorization to send notifications on a trial basis. Users can then evaluate the notifications and decide whether to authorize them.


```js
Notifications.ios.registerRemoteNotifications(['ProvidesAppNotificationSettings']);
Notifications.ios.registerRemoteNotifications([
'ProvidesAppNotificationSettings',
'Provisional',
]);
```

## checkPermissions()
Expand Down