-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[unimodules][android][notifications] Event listener can miss emit()
calls made soon after app launch
#9866
Comments
emit()
calls made soon after app launchemit()
calls made soon after app launch
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Got it, so for ios is there any work around at the moment (besides ejecting)? I suppose checking for exp.notification and using that is better than nothing. |
Using the legacy notifications API listener works, as well. Other than that there's no workaround besides waiting for SDK 39 🙁 sorry that you pretty much just have to wait |
Thank you for reply, yes this works. Just to clarify - to test any changes related to handling notifications when app is killed I have 2 options 1) eject from expo and test locally 2) create expo build. No other options, correct? Thanks again for your help |
You can also run |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I opened this new issue to try and keep the conversation focused around the root issue, and this thread is turning into troubleshooting one of the resulting problems, which I've already shared the answer for in the original issue- #6943. Any comments posted here that are answered in the other issue will be marked as off-topic (sorry to do this, but too many off-topic comments makes discussing the original issue I posted much more difficult) @arveenkumar55 please refer to this comment @xLesterGG as far as I know there's no problem running |
Hi @cruzach, Thanks |
It is noted in the React documentation that https://reactjs.org/docs/hooks-reference.html#timing-of-effects As such I have tested Further to that, my specific implementation to navigate on notification was rather inconvenient when being placed outside the navigation container. For any others who have this issue and use ReactNavigation, my specific workaround here was to make a navigation container ref with a promise version, allowing await for the navigation to be mounted before completing the notification handling. Setup the ref for the navigation container (ignore the typescript typings if relevant), the navigation ref promise only resolves after items have been mounted inside the navigation container (this is reason for checking "getRootState())".
When processing the notification, if navigation data is present and results in a valid navigation action (based on navigation linking config), complete the navigation dispatch after the navigation ref promise has resolved.
|
Same problem here. Have also tried moving |
Hi, I too have the exact same issue. SDK 39 managed workflow. Tried it on standalone Android and iOS, inside useEffect or in the same place as Notifications.setNotificationHandler with no luck. If I can provide any other information to help find this issue please let me know. |
Confirming same problem as @KlasRobin, @antwaven, and @ozerty. Background/foreground work fine, just not when app is killed/not running. Also managed workflow, SDK 39. |
Hi @imhazige, I had issues on iOS 14, and still on Android for some reason (I think it had to do with the navigation mounting or something). I know this is not an ideal solution, but I switched to OneSignal for our app and it's been working great on both platforms (minus the typical FCM/APNs pitfalls, particularly slightly delayed notifications). This may be considered off-topic for the thread, but wanted to mention my success story just to indicate it as an option for you. Keep in mind it is a library with native bindings, so the Expo bare workflow is required if you choose to go that route. I have no doubt the Expo notifications API will continue to improve over time, but I did not have time to wait, unfortunately. |
Thank you for the response. I am using SDK40 and it works on android, for ios it seems to have this issue (#11343) need to be fixed. I have no choice for now as I have to bind to expo managed flow. Onesignal is better choice if I can use bareflow. |
…nly once JS subscribes to it (#11382) # Why Fixes a bug introduced in #10883 which causes initial notification responses to get lost in standalone iOS apps. Along with #11378 I believe it fixes #11343 and may also finally fix #9866. # How Using native breakpoints I've noticed `EXNotificationCenterDelegate`'s `addDelegate:` is called more times than I would expect it to. It turned out before `EXScopedNotificationsEmitter` was subscribing to `EXNotificationCenterDelegate` (it would then receive pending notification response) an unscoped `EXNotificationsEmitter` was subscribing and consuming pending responses. Since unscoped emitter wasn't being used and exposed to the app later, it consumed the response into the void. Most probably unimodules have a bug where instances of overridden modules are still kept in memory (since `setModuleRegistry:` is called on them). Fixing this bug is out of the scope of this pull request. These changes are based on how it was implemented before dfda625. I can't see any reason why `EXNotificationsEmitter` would need to register for notifications as soon as module registry is ready, so let's roll back to what we know worked well. # Test Plan I have verified in an ExpoKit workspace that when the app is opened from a notification, the notification response is delivered to `useLastNotificationResponse`: https://www.loom.com/share/586a906c538f47f0940b2cc83582fb29
…livered unless they're delivered to expo-notifications (#11378) # Why It's a nice counterpart to #11382 which ensures #11343 and #9866 do not happen again. # How Follow-up to #9478. There are two places where the notification response can be "consumed" — when it is received (covered by #9478) and when it is delivered to a new delegate (covered by this PR). # Test Plan I have verified in #11382 that workspace with this and #11382 changes delivers initial notification response to the app.
…nly once JS subscribes to it (#11382) # Why Fixes a bug introduced in #10883 which causes initial notification responses to get lost in standalone iOS apps. Along with #11378 I believe it fixes #11343 and may also finally fix #9866. # How Using native breakpoints I've noticed `EXNotificationCenterDelegate`'s `addDelegate:` is called more times than I would expect it to. It turned out before `EXScopedNotificationsEmitter` was subscribing to `EXNotificationCenterDelegate` (it would then receive pending notification response) an unscoped `EXNotificationsEmitter` was subscribing and consuming pending responses. Since unscoped emitter wasn't being used and exposed to the app later, it consumed the response into the void. Most probably unimodules have a bug where instances of overridden modules are still kept in memory (since `setModuleRegistry:` is called on them). Fixing this bug is out of the scope of this pull request. These changes are based on how it was implemented before dfda625. I can't see any reason why `EXNotificationsEmitter` would need to register for notifications as soon as module registry is ready, so let's roll back to what we know worked well. # Test Plan I have verified in an ExpoKit workspace that when the app is opened from a notification, the notification response is delivered to `useLastNotificationResponse`: https://www.loom.com/share/586a906c538f47f0940b2cc83582fb29
…livered unless they're delivered to expo-notifications (#11378) # Why It's a nice counterpart to #11382 which ensures #11343 and #9866 do not happen again. # How Follow-up to #9478. There are two places where the notification response can be "consumed" — when it is received (covered by #9478) and when it is delivered to a new delegate (covered by this PR). # Test Plan I have verified in #11382 that workspace with this and #11382 changes delivers initial notification response to the app.
Issue has been closed for fixes have been merged, please allow up to 24 hours for them to be available when you run As a foretaste and to some degree proof let me share with you this video — https://www.dropbox.com/s/u2ih7umzt1zbxbp/RPReplay_Final1608160452.mp4?dl=0 🙂 |
Fix has been deployed to production Turtle builders! 🎉 All iOS apps built after December 17, 2020, 15:45 UTC will have fixes included and should not longer suffer from this problem. This being said, let us know if this or similar problem ever rises again! |
@sjchmiela - Just upgraded to SDK 40 On my Galaxy S8, standalone app, managed, with Android Version 9 (I cannot upgrade the OS bc phone is not supported), the problem still persists. See above: #9866 (comment) Yes, I've also tried I've tried to make a minimal repro case but seems I can't reproduce it without the complexity of my app. Should I make a new issue for this? |
Can anyone tell me if they can do:
While background location updates are on, the notifications are not being received from a dead start. When I turned it off, it works. |
For me notifications aren't wotking even without location updates. I still use #9866 (comment) this workaround |
Some changes in the following packages that may fix this issue have just been published to npm under
If you're using bare workflow you can upgrade them right away. We kindly ask you for some feedback—even if it works 🙏 They will become available in managed workflow with the next SDK release 👀 Happy Coding! 🎉 |
Just to confirm, this works for me. on ios and android. have not see problem yet. |
But do you received a warning expected expo-notification V 0.8.2? |
will work with the expo SDK 40? |
@webuijorgeGL - #11382 is in sdk 40, if that's what you're looking for. you cannot, however, use expo-notifications 0.9.0 in sdk 40 - that includes other changes (see the changelog). https://github.com/expo/expo/blob/sdk-40/packages/expo/bundledNativeModules.json#L103 |
Still doesn't work with latest SDK |
Any news ? |
@MrIceman @Guilhemfuel Just use the |
It doesn't work either on background and killed. The response will be null... |
Have you found a workaround for this issue? |
🐛 Bug Report
Summary of Issue
If you call
Notifications.addResponseReceivedListener
inuseEffect
for example, the listener will not be triggered when opening an app from a completely killed state via a notification. This can also be demonstrated by adding a timeout tocomponentDidMount
as shown here. Without 1 second timeout- events come through; with 1 second timeout- event's do not come through.I should note that the emit method is getting called in this case.
Environment - output of
expo diagnostics
& the platform(s) you're targetingReproducible Demo
https://snack.expo.io/@charliecruzan/push-notifications
Steps to Reproduce
Need to run the app as a published experience or standalone app (or bare debug build) to see the behavior. Press "show notification" and kill the app, tap the notification, observe that response listener isn't triggered.
Workaround
The workaround (and possibly long-term solution) is to add the listener outside of any component, then it works as expected (presumably bc of how much sooner it's getting called?). I changed the docs to suggest this so fewer people run into this issue
The text was updated successfully, but these errors were encountered: