question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addNotificationResponseReceivedListener and useLastNotificationResponse not triggered for killed Standalone iOS and Android apps

See original GitHub issue

Summary

SDK Version: 41 Platforms ios/android Package “expo-notifications”: “~0.11.6”,

If you call Notifications.addResponseReceivedListener or useLastNotificationResponse in useEffect for example, the listener will not be triggered when opening an app from a completely killed state via a notification.

I tried addNotificationResponseReceivedListener, legacy.addListener (expo 40), useLastNotificationResponse, delay 1~10secs, or async await but all method doesn’t work.

app foreground ✅ app backgrounded ✅ app killed

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android, iOS

SDK Version (managed workflow only)

41

Environment

Expo CLI 4.4.3 environment info: System: OS: Windows 10 10.0.19041 Binaries: Node: 14.8.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 4.1.0.0 AI-201.8743.12.41.7042882 npmPackages: expo: ^41.0.0 => 41.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 react-navigation: ^4.4.4 => 4.4.4 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

  1. addNotificationResponseReceivedListener
useEffect(() => {
    const _notificationSubscription = Notifications.addNotificationResponseReceivedListener(
      (notification) => {
       
             console.log("hi");

      }
    );
    return () => _notificationSubscription.remove();
  }, []);
  1. addListener
_notificationSubscription = Notifications.addListener((notification) => {
     if (notification["origin"] === "selected") {
            console.log("hi");
      }
   });
  1. useLastNotificationResponse
const lastNotificationResponse = Notifications.useLastNotificationResponse();
  useEffect(() => {
    if (
      lastNotificationResponse &&
      lastNotificationResponse.notification.request.content.data &&
      lastNotificationResponse.actionIdentifier ===
        Notifications.DEFAULT_ACTION_IDENTIFIER
    ) {
      console.log("hi");
    }
    return () => backHandler.remove();
  }, [lastNotificationResponse]);

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
cruzachcommented, Jun 18, 2021

hi @VeecotechBrandon , this issue has been reported before and it’s usually due to the fact that the listeners aren’t being added soon enough after app start. You should add these listeners in as soon as possible to avoid missing notification responses.

Can you build a totally blank app with just the code from the example snack and verify for me that you still don’t get the responses?

I just tested this myself using that snack code, and this simulator build, and you can see that the response listener is triggered even when the app was killed. Just open the app, click the button, kill the app, then tap the notification.

3reactions
cruzachcommented, Jun 21, 2021

Closing for now for lack of reproducible demo, but I’m happy to reopen and investigate if you can provide a full demo using a blank expo init project like we ask for

Read more comments on GitHub >

github_iconTop Results From Across the Web

[expo-notifications] No notification data if app is killed or inactive
It seems to work fine for us on iOS, but we don't get anything when the app is either inactive or has been...
Read more >
Expo notification doesnt fire method when app is killed/closed
The problem is that the useEffect() get called too late after the app has finished initializing. Therefore the listener is not added before ......
Read more >
How to handle notifications when the app is backgrounded ...
When using a standalone app NotificationReceivedListener and NotificationResponseReceivedListener events are fired when foregrounded only. Is ...
Read more >
Basics and caveats of Expo-notifications - DEV Community ‍ ‍
Unfortunately, I did not test that but considering that the app triggers a local notification to display in the device when a push...
Read more >
expo-notifications-bux-fix v0.12.0 - npm.io
Then head over to android/app/src/main/AndroidManifest.xml and add a <meta-data> ... This is outside of expo-notifications 's control, as stated in Apple's ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found