Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce property on RCTPushNotificationManager to hold notification…
… that launched the app (#42628) Summary: Pull Request resolved: #42628 Changelog: [iOS][Deprecated] Retrieving initial notification requires UNUserNotificationCenterDelegate setup instead of reading UIApplicationLaunchOptionsLocalNotificationKey # how to migrate: if you are currently using `getInitialNotification` to check the notification on an app start (warm or cold), you will need to do a migration. have an object become the delegate of `UNUserNotificationCenterDelegate`. you can use your app's `AppDelegate` to do this. then, override `userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:`. in the implementation, add these lines: if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) { id module = _reactHost ? [[_reactHost getModuleRegistry] moduleForName:"PushNotificationManager"] : [_bridge moduleForClass:[RCTPushNotificationManager class]]; if ([module isKindOfClass:[RCTPushNotificationManager class]]) { RCTPushNotificationManager *pushNotificationManager = (RCTPushNotificationManager *)module; pushNotificationManager.initialLocalNotification = response.notification; } } # reasoning: when you start an app from a push notification, the `UIApplicationLaunchOptionsLocalNotificationKey` in `application:didFinishLaunchingWithOptions:` will contain the notification metadata that started the app. additionally, this was stored on the bridge, which is not compatible with the new architecture. however, `UIApplicationLaunchOptionsLocalNotificationKey` has been deprecated since iOS 10, which this PR aims to address. apple's supported API to do this is `userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:` which is on `UNUserNotificationCenterDelegate`. this is a significant change from a pull to push model. in order to make this change without having to rearchitect the product layer, we're going to store the notification on the notification native module. another caveat is that the API follows the delegation pattern, not the listener pattern. that means we can't make our notificaiton native module the delegate here - the app will probably need `UNUserNotificationCenterDelegate` to be a top level object - usually the scope of the app delegate. in future, i actually think we need to unify this with `handleLocalNotificationReceived:`, but right now there's forked handling between platforms and some product code is only using the pull model, so this is still the minimum change in the product layer. Reviewed By: ingridwang Differential Revision: D52897071 fbshipit-source-id: 579578d1b3128c5f7e81249c75cf7655b8e360e2
- Loading branch information