expo: [expo-notifications][bare workflow] Listener registered by addNotificationResponseReceivedListener() doesn't fire when the app is closed and then opened by tapping the push notification
đ Bug Report
Environment
| software | version |
|---|---|
| expo | detached to bare RN app |
| react-native | 0.61.5 |
| expo-notifications | 0.1.1 |
| platform OS | iOS |
Steps to Reproduce
According to the documentation listeners registered by addNotificationResponseReceivedListener(listener: (event: NotificationResponse) => void): void will be called whenever a user interacts with a notification (eg. taps on it).
If the app was closed (not in the background) and then opened by tapping the push notification, listener registered by this method will not be called.
Expected Behavior
Callback for addNotificationResponseReceivedListener should fire on the next tick after the app starts with the notification data, in the same way as Notifications.addListener() from managed workflow works. To be able to update the UI based on the notification, or maybe navigate to a particular screen when a notification was selected.
Actual Behavior
When the user taps on push notification when the app is killed, that just launch the app and listener doesnât trigger.
If there are any other ways to handle such a case with expo-notifications, please tell us.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 8
- Comments: 45 (18 by maintainers)
I have the same issue as @kale94 Both
addNotificationReceivedListenerandaddNotificationResponseReceivedListenerdoes not work in Android at all while the same code work perfectly in iOSTested with Android 9, Pixel 3 in Standalone build
@sjchmiela, with 0.1.6 release Iâm able to receive notifications when app is in foreground in the callback in Notifications.addNotificationReceivedListener(). However, Iâm still not able to receive any notifications when app is in background and opened by clicking the app icon or the notification bar.
OS: Android version 10 Device: Google Pixel 3
Any suggestions?
i maded a mistake with app.json on android
Open your app.json and add the following inside of the âexpoâ field:
@sjchmiela
addNotificationResponseReceivedListenercatches push notification by pressing on which you opened the app, but only if you add listener just after the app start. When you add listener after some delay (300ms) âinitialâ push notification will be ignored.So, this works
and this doesnât
Catching âinitialâ notification is needed when it has attached deep link and you need to navigate on it just after app start.
In our app we donât attach any notification listener during the loading time (fonts, persisted state, etc.). Usually it takes 300-500ms to finish loading and then we attach notification listener. So, the bug was that this listener doesnât catch âinitialâ notification. But we made a workaround and now everything works fine.
If you think that this is not a real issue feel free to close it (the main problem could be with backward compatibility with
Expo.Notificationsas they were handling this âdelay-caseâ). You can also rename this issue in a more descriptive way.P.S. Thank you for
expo-notificationsin general đWhat worked for me was just writing the Notifications functions outside the main App() function.
It worked outside of componentâŚ
expo-notifications@0.1.3-rc.0is now available. Note that (at least I) had to do some magic to make Xcode rebuild the Pods project â you may need to <kbd>Product</kbd> > <kbd>Clean build folder</kbd> to use the updated code (I also had to remove the app from the simulator on which I was testing the fix đ¤ˇ) (if it works for you without all this hacks, great!).Hey, sorry for making you go through this problem, I have introduced a bug to the implementation at the last stage of developing so I didnât notice it â I have reproduced the bug and I think I also fixed it.
Would you mind checking if applying this patch with
patch-packagesolves the problem for you?I will publish
expo-notifications@0.1.3-rc.0with this fix and let you know when itâs ready to be tested.