addNotificationResponseReceivedListener or useLastNotificationResponse is not firing when app is killed

See original GitHub issue

Summary

Both useLastNotificationResponse hook and addNotificationResponseReceivedListener isn’t firing when my expo app is killed. Working only in background and foreground. My expo-notifications package is up-to-date : “^0.9.0”.

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)

40.0.1

Environment

Expo CLI 4.1.6 environment info: System: OS: macOS 10.15.5 Shell: 3.2.57 - /bin/bash Binaries: Node: 14.8.0 - ~/.nvm/versions/node/v14.8.0/bin/node npm: 6.14.7 - ~/.nvm/versions/node/v14.8.0/bin/npm SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 4.1 AI-201.8743.12.41.7042882 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: expo: ^40.0.1 => 40.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-40.0.1.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 npmGlobalPackages: expo-cli: 4.1.6 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

Notifications.setNotificationHandler({
	handleNotification: async () => ({
		shouldShowAlert: true,
		shouldPlaySound: false,
		shouldSetBadge: false,
	}),
});

Notifications.addNotificationResponseReceivedListener((response) => {
  console.log("received response!", response);
});

const handlePush = async ({ notification }) => {
	console.log("navigate");
}


export default function App() {


	const lastNotificationResponse = Notifications.useLastNotificationResponse();

	React.useEffect(() => {
		console.log(lastNotificationResponse);
					if (lastNotificationResponse && lastNotificationResponse.actionIdentifier === Notifications.DEFAULT_ACTION_IDENTIFIER) {
					handlePush(lastNotificationResponse);
			}
	}, [lastNotificationResponse]);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
bondansebastiancommented, Feb 16, 2022

I still experienced this issue on SDK 44 (managed)

0reactions
appsgeniecommented, Oct 7, 2022

On SDK43 I was unsuccessful to capture the event with addNotificationResponseReceivedListener on Android when the app was killed. I tried to register the listener in a useLayoutEffect instead of an useEffect but that changed nothing.

Desperately I tried the useLastNotificationResponse out instead of manually register eventListeners and I was able to receive and handle notifications on Android when the app was in a “killed” state.

My original approach was to register addNotificationReceivedListener and addNotificationResponseReceivedListener for both iOS and Android.

  • On iOS I was able to capture and handle events on all app states (foreground, background and killed).
  • On Android I was able to capture and handle events in the foreground, background.

My final approach:

  • addNotificationReceivedListener and addNotificationResponseReceivedListener was used to capture and handle events on iOS as that seemed to work perfectly.
  • addNotificationReceivedListener and useLastNotificationResponse was used to capture and handle events on Android.

It certainly seems like the addNotificationResponseReceivedListener problem is still not resolved.

How did you use useLastNotificationResponse? Was it in same place as addNotificationReceivedListener for Android? And do you know how to get that working with class components?

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 ...
Push notification doesn't open specific screen when app is killed, ... and useLastNotificationResponse not triggered for killed Standalone ...
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 >
Basics and caveats of Expo-notifications - DEV Community ‍ ‍
local notifications: notifications triggered by the app installed in a ... in the foreground and background, but not when the app is killed....
Read more >
Advanced: Notifications: SUCCESSFUL CODE - React Native
app.json: ... addNotificationResponseReceivedListener(response ... a notification (works when app is foregrounded, backgrounded, or killed) ...
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