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

Exposes new event: remoteNotificationsRegistrationDenied #845

Merged
merged 3 commits into from
Mar 24, 2022
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
1 change: 1 addition & 0 deletions lib/ios/RNEventEmitter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import <React/RCTEventEmitter.h>

static NSString* const RNRegistered = @"remoteNotificationsRegistered";
static NSString* const RNRegistrationDenied = @"remoteNotificationsRegistrationDenied";
static NSString* const RNRegistrationFailed = @"remoteNotificationsRegistrationFailed";
static NSString* const RNPushKitRegistered = @"pushKitRegistered";
static NSString* const RNNotificationReceived = @"notificationReceived";
Expand Down
1 change: 1 addition & 0 deletions lib/ios/RNEventEmitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ @implementation RNEventEmitter

-(NSArray<NSString *> *)supportedEvents {
return @[RNRegistered,
RNRegistrationDenied,
RNRegistrationFailed,
RNPushKitRegistered,
RNNotificationReceived,
Expand Down
4 changes: 4 additions & 0 deletions lib/ios/RNNotificationCenter.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "RNEventEmitter.h"
#import "RNNotificationCenter.h"
#import "RCTConvert+RNNotifications.h"

Expand Down Expand Up @@ -40,6 +41,9 @@ - (void)requestPermissions:(NSDictionary *)options {
}
}];
}
if (!error && !granted) {
[RNEventEmitter sendEvent:RNRegistrationDenied body:nil];
}
}];
}

Expand Down
8 changes: 6 additions & 2 deletions lib/src/adapters/NativeEventsReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export class NativeEventsReceiver {
}

public registerNotificationReceived(callback: (notification: Notification) => void): EmitterSubscription {
return this.emitter.addListener('notificationReceived', (payload) => {
return this.emitter.addListener('notificationReceived', (payload: unknown) => {
callback(this.notificationFactory.fromPayload(payload));
});
}

public registerNotificationReceivedBackground(callback: (notification: Notification) => void): EmitterSubscription {
return this.emitter.addListener('notificationReceivedBackground', (payload) => {
return this.emitter.addListener('notificationReceivedBackground', (payload: unknown) => {
callback(this.notificationFactory.fromPayload(payload));
});
}
Expand All @@ -50,4 +50,8 @@ export class NativeEventsReceiver {
public registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription {
return this.emitter.addListener('remoteNotificationsRegistrationFailed', callback);
}

public registerRemoteNotificationsRegistrationDenied(callback: () => void): EmitterSubscription {
return this.emitter.addListener('remoteNotificationsRegistrationDenied', callback);
}
}
4 changes: 4 additions & 0 deletions lib/src/events/EventsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ export class EventsRegistry {
public registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription {
return this.nativeEventsReceiver.registerRemoteNotificationsRegistrationFailed(callback);
}

public registerRemoteNotificationsRegistrationDenied(callback: () => void): EmitterSubscription {
return this.nativeEventsReceiver.registerRemoteNotificationsRegistrationDenied(callback);
}
}
9 changes: 9 additions & 0 deletions website/docs/api/general-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,13 @@ Fired when the user fails to register for remote notifications. Typically occurs
Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
console.log(event.code, event.localizedDescription, event.domain);
});
```

## registerRemoteNotificationsDenied()
Fired when the user does not grant permission to receive push notifications. Typically occurs when pressing the "Don't Allow" button in iOS permissions overlay.

```js
Notifications.events().registerRemoteNotificationRegistrationDenied(() => {
console.log('Notification permissions not granted')
})
```