addNotificationResponseReceivedListener is not working when app is opened from killed state
See original GitHub issueSummary
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:
- Created a year ago
- Comments:6
Top Related StackOverflow Question
Same issue here. I tried multiple things (including putting
useLastNotificationResponseandaddNotificationResponseReceivedListenerat the top of the chain) and nothing seems to work. On Android standalone when app is killed it will never fire these…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 :
seems to have no effect