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

Introduce new notification callback in RCTPushNotificationManager #42405

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,34 @@ extern NSString *const RCTRemoteNotificationReceived;
typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);

+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
/**
* Triggers remoteNotificationReceived or localNotificationReceived events.
*
* Call this method from UNUserNotificationCenterDelegate's
* `userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:` in order to process a user tap on a
* notification.
*
* To process notifications received while the app is in the foreground, call this method from
* `userNotificationCenter:willPresentNotification:withCompletionHandler:`. Use the completion handler to determine if
* the push notification should be shown; to match prior behavior which does not show foreground notifications, use
* UNNotificationPresentationOptionNone.
*
* If you need to determine if the notification is remote, check that notification.request.trigger
* is an instance of UNPushNotificationTrigger.
*/
+ (void)didReceiveNotification:(UNNotification *)notification;
/**
* Call this from your app delegate's `application:didReceiveRemoteNotification:fetchCompletionHandler:`. If you
* implement both that method and `userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:`, only
* the latter will be called.
*/
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler;
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification;
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;

/** DEPRECATED. Use didReceiveNotification instead. */
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification RCT_DEPRECATED;
/** DEPRECATED. Use didReceiveNotification instead. */
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification RCT_DEPRECATED;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -230,30 +230,49 @@ + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
userInfo:@{@"error" : error}];
}

+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
{
NSDictionary *userInfo = @{@"notification" : notification};
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
object:self
userInfo:userInfo];
+ (void)didReceiveNotification:(UNNotification *)notification
{
BOOL const isRemoteNotification = [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]];
if (isRemoteNotification) {
NSDictionary *userInfo = @{@"notification" : notification.request.content.userInfo};
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
object:self
userInfo:userInfo];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived
object:self
userInfo:RCTFormatUNNotification(notification)];
}
}

+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler
{
NSDictionary *userInfo = @{@"notification" : notification, @"completionHandler" : completionHandler};
NSDictionary *userInfo = completionHandler
? @{@"notification" : notification, @"completionHandler" : completionHandler}
: @{@"notification" : notification};
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
object:self
userInfo:userInfo];
}

// Deprecated
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification
{
[[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived
object:self
userInfo:RCTFormatLocalNotification(notification)];
}

// Deprecated
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
{
NSDictionary *userInfo = @{@"notification" : notification};
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
object:self
userInfo:userInfo];
}

- (void)handleLocalNotificationReceived:(NSNotification *)notification
{
[self sendEventWithName:@"localNotificationReceived" body:notification.userInfo];
Expand Down