Skip to content

Commit

Permalink
Migrate RNTester onto new RN notification callbacks (#42406)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42406

## Changelog:

[iOS][Changed] Migrated RNTester/AppDelegate to the new notification callback

Reviewed By: philIip

Differential Revision: D52883367

fbshipit-source-id: 0afcd81f4ad4ee0c49b264785fa261789603a072
  • Loading branch information
Ingrid Wang authored and facebook-github-bot committed Jan 24, 2024
1 parent d46d80d commit ccff2bb
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/rn-tester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#import "AppDelegate.h"

#import <UserNotifications/UserNotifications.h>

#import <React/RCTBundleURLProvider.h>
#import <React/RCTDefines.h>
#import <React/RCTLinkingManager.h>
Expand All @@ -22,6 +24,9 @@

static NSString *kBundlePath = @"js/RNTesterApp.ios";

@interface AppDelegate () <UNUserNotificationCenterDelegate>
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Expand All @@ -31,6 +36,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// They will be passed down to the ViewController used by React Native.
self.initialProps = [self prepareInitialProps];

[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];

return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

Expand Down Expand Up @@ -96,17 +103,26 @@ - (void)application:(__unused UIApplication *)application
[RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
}

// Required for the remoteNotificationReceived event.
- (void)application:(__unused UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
#pragma mark - UNUserNotificationCenterDelegate

// Required for the remoteNotificationReceived and localNotificationReceived events
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[RCTPushNotificationManager didReceiveRemoteNotification:notification];
[RCTPushNotificationManager didReceiveNotification:notification];
completionHandler(UNNotificationPresentationOptionNone);
}

// Required for the localNotificationReceived event.
- (void)application:(__unused UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
// 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.)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RCTPushNotificationManager didReceiveLocalNotification:notification];
[RCTPushNotificationManager didReceiveNotification:response.notification];
completionHandler();
}

#pragma mark - New Arch Enabled settings
Expand Down

0 comments on commit ccff2bb

Please sign in to comment.