OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.57k stars 373 forks source link

Use RNFirebase with OneSignal - iOS #958

Closed rborn closed 4 years ago

rborn commented 4 years ago

Description: I am trying to use RNFirebase local scheduled notification in the same time with remote notifications from OneSignal.

The issue is that while the local scheduled notification is displayed I don't receive any callback event. This only happens on iOS, on android it works so far.

I tried everything I could (my objC-fu is not as good) but I could not manage to make it work.

At some point I added [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; and onNotificationOpened started to trigger however OneSignal stopped to work :(

I also tried to disable swizzling in Firebase but it made no difference.

Any help or idea would be appreciated, I'm kind of stuck here and don't know how to fix this. Thank you 😻

Environment

OneSignal React-Native SDK : 3.6.5 RNFirebase: 5.6.0

rborn commented 4 years ago

@rgomezp @Nightsd01 could you give me some help this? OneSignal is not providing a way to make local notifications and postMessage is not an option for us (it has to be a reminder, locally on the device)

No matter what I try I don't manage to make this work - spent already a few days only on this- and my objC is pretty rusty :( Thanks in advance!

rborn commented 4 years ago

fwiw I tried also https://github.com/react-native-community/react-native-push-notification-ios . Same result, no luck :(

jkasten2 commented 4 years ago

@rborn OneSignal does swizzle the UNUserNotificationCenter so even if you have [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; in your code it shouldn't break OneSignal. https://github.com/OneSignal/OneSignal-iOS-SDK/blob/2.12.6/iOS_SDK/OneSignalSDK/Source/UNUserNotificationCenter%2BOneSignal.m#L74 Could you share your code where you are calling this?

Before I dig into the code to far RNFirebase is this RNFirebase: 5.6.0? https://github.com/invertase/react-native-firebase

I looked at the setup guide for react-native-push-notification-ios and it is incomplete. https://github.com/react-native-community/react-native-push-notification-ios/blob/9fbb9beeb9c65243e3462bd7a7da5d9ef2ecff72/README.md#update-appdelegatem

When you setup the 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. https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622930-application?language=objc

rborn commented 4 years ago

@jkasten2 thanks, yes it's 5.6.0 (didn't move to 6 as it doesn't have notifications) I have some results with react-native-push-notification-ios and tried to replicate them to RNFirebase but is not fully working.

react-native-push-notification-ios also has issues to get the initialNotification but I found a workaround (they seem not wait for RN to initialise so the info is lost)

rborn commented 4 years ago

@jkasten2 small update, I managed to do "something" with react-native-push-notification (that mixes react-native-push-notification-ios and own android code ) but it's not ideal as they have both bugs and/or are old modules and I need to workaround many things. It also means I need to add another module to the app which adds weight.

I tried to replicate what I did with the RNFirebase v5.6.0 module but I only have very limited results.

It would be amazing to manage to make it work (even if in time will become obsolete as v6 won't have notifications soon) and have it in one place only. Maybe you could take a look ?

Ideally I think OneSignal could implement localNotifications, even if it's not the scope but would give a lot of value to the devs and way less Github issues for you guys 😊

I'm not a native guy but I can help with testing in case you decide to do something about this 🤗 Thank you.

rgomezp commented 4 years ago

Thanks for your suggestion @rborn . We will definitely take your suggestion into consideration.

Can you provide more details regarding the "limited results" you are seeing? What behavior is occurring?

Edit: also, please upvote this issue with React Native

rborn commented 4 years ago

@rgomezp hi, thanks for the reply By "limited results" I mean I'm not able to make it work, the local notification executes (I see it in the native logs) but (due to the delegate I think) is not triggering any event or notification.

rgomezp commented 4 years ago

Howdy @rborn, My pleasure. Is it okay if I close this issue and you can just follow the progress in the React Native repo issue?

rborn commented 4 years ago

@rgomezp Ok, thank you. What about the local notifications directly from OneSignal, any plans for this?

rgomezp commented 4 years ago

Howdy @rborn, Currently, no. Not because we don't want to but rather simply due to bandwidth. It is definitely something we will consider for the future. Thanks for the suggestion!