addNotificationResponseReceivedListener and useLastNotificationResponse not triggered for killed Standalone iOS and Android apps
See original GitHub issueSummary
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
- addNotificationResponseReceivedListener
useEffect(() => {
const _notificationSubscription = Notifications.addNotificationResponseReceivedListener(
(notification) => {
console.log("hi");
}
);
return () => _notificationSubscription.remove();
}, []);
- addListener
_notificationSubscription = Notifications.addListener((notification) => {
if (notification["origin"] === "selected") {
console.log("hi");
}
});
- 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
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.
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