-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[Push notifications] Add error event #7694
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ var _initialNotification = RCTPushNotificationManager && | |
|
||
var DEVICE_NOTIF_EVENT = 'remoteNotificationReceived'; | ||
var NOTIF_REGISTER_EVENT = 'remoteNotificationsRegistered'; | ||
var NOTIF_REGISTER_ERROR_EVENT = 'remoteNotificationsRegisteredError'; | ||
var DEVICE_LOCAL_NOTIF_EVENT = 'localNotificationReceived'; | ||
|
||
/** | ||
|
@@ -153,8 +154,8 @@ class PushNotificationIOS { | |
*/ | ||
static addEventListener(type: string, handler: Function) { | ||
invariant( | ||
type === 'notification' || type === 'register' || type === 'localNotification', | ||
'PushNotificationIOS only supports `notification`, `register` and `localNotification` events' | ||
type === 'notification' || type === 'register' || type === 'localNotification' || type === 'error', | ||
'PushNotificationIOS only supports `notification`, `register`, `error` and `localNotification` events' | ||
); | ||
var listener; | ||
if (type === 'notification') { | ||
|
@@ -178,6 +179,13 @@ class PushNotificationIOS { | |
handler(registrationInfo.deviceToken); | ||
} | ||
); | ||
} else if(type === 'error'){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a space between |
||
listener = RCTDeviceEventEmitter.addListener( | ||
NOTIF_REGISTER_ERROR_EVENT, | ||
(registrationError) => { | ||
handler(registrationError); | ||
} | ||
); | ||
} | ||
_notifHandlers.set(handler, listener); | ||
} | ||
|
@@ -252,8 +260,8 @@ class PushNotificationIOS { | |
*/ | ||
static removeEventListener(type: string, handler: Function) { | ||
invariant( | ||
type === 'notification' || type === 'register' || type === 'localNotification', | ||
'PushNotificationIOS only supports `notification`, `register` and `localNotification` events' | ||
type === 'notification' || type === 'register' || type === 'localNotification' || type === 'error', | ||
'PushNotificationIOS only supports `notification`, `register`, `error` and `localNotification` events' | ||
); | ||
var listener = _notifHandlers.get(handler); | ||
if (!listener) { | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -27,6 +27,7 @@ | |||
NSString *const RCTLocalNotificationReceived = @"LocalNotificationReceived"; | ||||
NSString *const RCTRemoteNotificationReceived = @"RemoteNotificationReceived"; | ||||
NSString *const RCTRemoteNotificationsRegistered = @"RemoteNotificationsRegistered"; | ||||
NSString *const RCTRemoteNotificationRegisteredError = @"RemoteNotificationRegisteredError"; | ||||
|
||||
@implementation RCTConvert (UILocalNotification) | ||||
|
||||
|
@@ -85,6 +86,10 @@ - (void)setBridge:(RCTBridge *)bridge | |||
selector:@selector(handleRemoteNotificationsRegistered:) | ||||
name:RCTRemoteNotificationsRegistered | ||||
object:nil]; | ||||
[[NSNotificationCenter defaultCenter] addObserver:self | ||||
selector:@selector(handleRemoteNotificationRegisteredError:) | ||||
name:RCTRemoteNotificationRegisteredError | ||||
object:nil]; | ||||
} | ||||
|
||||
- (NSDictionary<NSString *, id> *)constantsToExport | ||||
|
@@ -135,6 +140,15 @@ + (void)didReceiveLocalNotification:(UILocalNotification *)notification | |||
userInfo:details]; | ||||
} | ||||
|
||||
|
||||
|
||||
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you the update the documentation in
|
||||
{ | ||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationRegisteredError | ||||
object:self | ||||
userInfo:error.userInfo]; | ||||
} | ||||
|
||||
- (void)handleLocalNotificationReceived:(NSNotification *)notification | ||||
{ | ||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"localNotificationReceived" | ||||
|
@@ -153,6 +167,12 @@ - (void)handleRemoteNotificationsRegistered:(NSNotification *)notification | |||
body:notification.userInfo]; | ||||
} | ||||
|
||||
- (void)handleRemoteNotificationRegisteredError:(NSNotification *)notification | ||||
{ | ||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"remoteNotificationsRegisteredError" | ||||
body:[notification userInfo]]; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Judging by the preceding notification handlers, dot-notation is preferred: |
||||
} | ||||
|
||||
/** | ||||
* Update the application icon badge number on the home screen | ||||
*/ | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name doesn’t really read nicely. What about a name like
remoteNotificationsRegistrationError
(and in all other places in the code) ?