invertase / react-native-notifee

Moved to https://github.com/invertase/notifee
https://invertase.io/blog/open-sourcing-notifee
Other
466 stars 31 forks source link

[IOS] getInitialNotification method not consistent when used with react-native-splash-screen #288

Closed antoinefBam closed 3 years ago

antoinefBam commented 3 years ago

This problem was already spotlighted here in this repo. I wasted some time getting to the root of the problem so that's why I prefer to open an issue that clearly references this concern.

I know react-native-splash-screen is not actively maintained anymore but I am working on a project that is a bit old and have been using this library for a long time without ever having any problems.

Since then, notifications have become a central feature of the application. We use FCM coupled with Notifee to display notifications and handle opening events in all app states (foreground, background and killed) both on IOS and Android.

On IOS I noticed some inconsistency when attempting to get the involved notification using notifee.getInitialNotification() after clicking on a notification from a killed app state. Most of the time the method returns null.

After removing react-native-splash-screen the problem seems to be gone (tested locally on a real device for now). My next steps to confirm this hypothesis is to switch to react-native-bootsplash and deploy a new release build. I come back to you to confirm that everything is good 👍

helenaford commented 3 years ago

oh interesting - i'm not sure why that would be an issue but yes, definitely recommend using react-native-bootsplash over the other library. Please let us know if you still have the issue.

mikehardy commented 3 years ago

This came up in react-native-firebase recently. In the docs there it states getInitialNotification must be used within the React lifecycle, and if not you may not get the expected results. Perhaps that is the case here?

https://rnfirebase.io/messaging/notifications#handling-interaction

The call to getInitialNotification should happen within a React lifecycle method after mounting (e.g. componentDidMount or useEffect). If it's called too soon (e.g. within a class constructor or global scope), the notification data may not be available.

antoinefBam commented 3 years ago

Hi again,

Yes getInitialNotification should be used within the React lifecycle. Classic use case is to call it inside an effect in the landing page of the app on opening and make the appropriate redirection accordingly.

To return to the initial concern I:

I lack knowledge in native IOS development to explain precisely the link between splash screen and notifications opening. Any explanation would be welcome. I think we can close this issue for now.

mikehardy commented 3 years ago

the react-native-splash-screen module was doing something fundamentally wrong on the Android side so I did not even inspect the iOS side - I am just going to have to leave it at "I am not that surprised" and we'll all move on :-), Really happy to hear it's working for you now!