addNotificationResponseReceivedListener is not working when app is opened from killed state

See original GitHub issue

Summary

I have followed the example provided from Expo notification module to setup local push notifications. The notification linking works as expected if the app is in the background, but if the app is opened from killed state the addNotificationResponseReceivedListener is not fired as referred in developer documentation.

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

SDK Version (managed workflow only)

44

Environment

expo-env-info 1.0.5 environment info: System: OS: macOS 10.15.7 Shell: 5.7.1 - /bin/zsh Binaries: Node: 14.19.1 - ~/.nvm/versions/node/v14.19.1/bin/node npm: 6.14.16 - ~/.nvm/versions/node/v14.19.1/bin/npm SDKs: iOS SDK: Platforms: iOS 13.7, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 IDEs: Xcode: 11.7/11E801a - /usr/bin/xcodebuild npmPackages: expo: ~44.0.0 => 44.0.6 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 Expo Workflow: managed

Reproducible demo

const triggerNotification = () => {
 
  Notifications.scheduleNotificationAsync({
    content: {
      title: "Notification title",
      body: `Some body content`,
      data: { name: "Joe", age: "24" },
    },
    trigger: {
      seconds: 60,
      repeats: true,
    },
  });
};



useEffect(() => {
    registerForPushNotificationsAsync().then((token) =>
      setExpoPushToken(token)
    );

    notificationListener.current =
      Notifications.addNotificationReceivedListener((notification) => {
        setNotification(notification);
      });

    responseListener.current =
      Notifications.addNotificationResponseReceivedListener((response) => {
        console.log(response);
      });

   
     triggerNotification();
  
    return () => {
      Notifications.removeNotificationSubscription(
        notificationListener.current
      );
      Notifications.removeNotificationSubscription(responseListener.current);
    };
  }, []);

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
appsgeniecommented, Oct 7, 2022

Same issue here. I tried multiple things (including putting useLastNotificationResponse and addNotificationResponseReceivedListener at the top of the chain) and nothing seems to work. On Android standalone when app is killed it will never fire these…

0reactions
JayMdscommented, Sep 22, 2022

I encounter the same issue with expo sdk46 (managed checking results on expo Go) and the :

notificationListener.current = Notifications.addNotificationReceivedListener(notification => { setNotification(notification); playSound() showAlert(sound) });

works well but :

  responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
        unloadSound()
        console.log(response);
    });

seems to have no effect

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Push notification doesn't open specific screen when app is ...
I have a problem where I need to redirect user to specific post when he taps on notification, but that only works when...
Read more >
Handle remote notifications when app is killed
When the app is killed, DidReceiveRemoteNotification() is not called, so we can not process the notification. However, the notification will be shown as...
Read more >
Adding notifications to your expo app - | Negative Epsilon
Push notifications are a fundamental part of any mobile app in order to ... our notifications working is getting an expo notification token....
Read more >
Expo Push Notification Foreground Not Working : r/reactnative
Hi all, my expo push notifications in the foreground aren't working. Background works, killed works. Foreground does not work.
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