react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
746 stars 285 forks source link

Usage with OneSignal #81

Open rborn opened 4 years ago

rborn commented 4 years ago

Question

I'm trying to use this with OneSignal - https://github.com/OneSignal/react-native-onesignal - but they seem to swizzle the push methods and localNotifications will break.

There are few issues where people have more or less success but I didn't manage to make it work. Does anyone know how to do this? 🥺

Thanks and sorry for the spam

jkasten2 commented 4 years ago

The setup guide for modifying the code in iOS's AppDelegate is incomplete. https://github.com/react-native-community/react-native-push-notification-ios/blob/9fbb9beeb9c65243e3462bd7a7da5d9ef2ecff72/README.md#update-appdelegatem

When you setup a UNUserNotificationCenter delegate you need to setup BOTH it's method and call the matching RNCPushNotificationIOS methods. That is because when a UNUserNotificationCenter delegate is set the matching AppDelgate methods won't fire. that is application:didReceiveLocalNotification and application:didReceiveRemoteNotification:fetchCompletionHandler: on the AppDelegate won't fire. This behavior is built into iOS, and UNUserNotificationCenter should be using going forward as these AppDelegate methods have been deprecated for a number of years, since iOS 10 was released. https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622930-application?language=objc

rborn commented 4 years ago

I'm onto something, I'll update when I'm done, thank you @jkasten2