Skip to content

Commit

Permalink
add example for capturing initial notification in push notification m…
Browse files Browse the repository at this point in the history
…anager (facebook#42687)

Summary:

Changelog: [Internal]

adding an example for if you want to use `getInitialNotification`.

Reviewed By: ingridwang

Differential Revision: D52931618
  • Loading branch information
philIip authored and facebook-github-bot committed Feb 13, 2024
1 parent 8a94bf0 commit aac3e04
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ - (BOOL)runtimeSchedulerEnabled
}

#pragma mark - UISceneDelegate

- (void)windowScene:(UIWindowScene *)windowScene
didUpdateCoordinateSpace:(id<UICoordinateSpace>)previousCoordinateSpace
interfaceOrientation:(UIInterfaceOrientation)previousInterfaceOrientation
Expand All @@ -207,6 +208,7 @@ - (void)windowScene:(UIWindowScene *)windowScene
}

#pragma mark - RCTCxxBridgeDelegate

- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
Expand Down
15 changes: 13 additions & 2 deletions packages/rn-tester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <UserNotifications/UserNotifications.h>

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTDefines.h>
#import <React/RCTLinkingManager.h>
Expand Down Expand Up @@ -116,12 +117,22 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center

// Required for the remoteNotificationReceived and localNotificationReceived events
// Called when a notification is tapped from background. (Foreground notification will not be shown per
// the presentation option selected above.)
// the presentation option selected above).
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RCTPushNotificationManager didReceiveNotification:response.notification];
UNNotification *notification = response.notification;

// This condition will be true if tapping the notification launched the app.
if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
RCTPushNotificationManager *pushNotificationManager = [self.bridge moduleForName:@"PushNotificationManager"
lazilyLoadIfNecessary:YES];
// This can be retrieved with getInitialNotification.
pushNotificationManager.initialNotification = notification;
}

[RCTPushNotificationManager didReceiveNotification:notification];
completionHandler();
}

Expand Down

0 comments on commit aac3e04

Please sign in to comment.