🐧 Linux TippsDebian 11 Long Term Support reaches end-of-life(31.08.2026 um 02:00 Uhr)
🐧 Linux TippsUpdated Debian 13: 13.7 released(12.09.2026 um 02:00 Uhr)
🕵️ SicherheitslückenUSN-8741-1: Flatpak vulnerabilities(10.09.2026 um 10:44 Uhr)
🕵️ SicherheitslückenUSN-8742-1: Netty vulnerability(10.09.2026 um 11:01 Uhr)
🕵️ SicherheitslückenUSN-8737-2: GNU C Library vulnerabilities(10.09.2026 um 13:25 Uhr)
🕵️ SicherheitslückenUSN-8743-1: PHP vulnerabilities(10.09.2026 um 13:48 Uhr)
🕵️ SicherheitslückenUSN-8744-1: Python vulnerabilities(10.09.2026 um 15:53 Uhr)
🐧 Linux TippsUSN-8748-1: Linux kernel (NVIDIA) vulnerabilities(10.09.2026 um 17:32 Uhr)
🕵️ SicherheitslückenUSN-8745-1: KissFFT vulnerabilities(10.09.2026 um 17:36 Uhr)
🕵️ SicherheitslückenUSN-8746-1: libEBML vulnerability(10.09.2026 um 17:48 Uhr)
🐧 Linux TippsDebian 11 Long Term Support reaches end-of-life(31.08.2026 um 02:00 Uhr)
🐧 Linux TippsUpdated Debian 13: 13.7 released(12.09.2026 um 02:00 Uhr)
🕵️ SicherheitslückenUSN-8741-1: Flatpak vulnerabilities(10.09.2026 um 10:44 Uhr)
🕵️ SicherheitslückenUSN-8742-1: Netty vulnerability(10.09.2026 um 11:01 Uhr)
🕵️ SicherheitslückenUSN-8737-2: GNU C Library vulnerabilities(10.09.2026 um 13:25 Uhr)
🕵️ SicherheitslückenUSN-8743-1: PHP vulnerabilities(10.09.2026 um 13:48 Uhr)
🕵️ SicherheitslückenUSN-8744-1: Python vulnerabilities(10.09.2026 um 15:53 Uhr)
🐧 Linux TippsUSN-8748-1: Linux kernel (NVIDIA) vulnerabilities(10.09.2026 um 17:32 Uhr)
🕵️ SicherheitslückenUSN-8745-1: KissFFT vulnerabilities(10.09.2026 um 17:36 Uhr)
🕵️ SicherheitslückenUSN-8746-1: libEBML vulnerability(10.09.2026 um 17:48 Uhr)

🔧 Programmierung 🕛 vor 1 Monat 3 Min Lesezeit
0

Handling Notification Taps in expo-notifications: Launch vs. Runtime

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

This article is an English translation of the original Japanese article.



When a user taps a push notification, the entry point differs depending on whether the app is running. If you only use one listener with Expo Router to navigate to the notification target screen, you may miss launches from the terminated state.



In my app, I handle both cases with two separate mechanisms:





  • getLastNotificationResponseAsync(): when the app launches from a notification tap


  • addNotificationResponseReceivedListener(): when a notification is tapped while the app is running






Structuring Notification Data



The notifications sent from the server include the destination path in data.url.




CODE
{
title: "Attendance Deadline Reminder",
body: "Please confirm your attendance for tomorrow's practice",
data: {
url: "/organizations/org_123/schedules/schedule_456"
}
}






Rather than parsing the displayed title or body to determine the destination, I pass a path the app can handle as separate data.






Handling Launch from Notification



When the app is in a terminated state, I check for the last notification response after launch.




CODE
void Notifications.getLastNotificationResponseAsync().then((response) => {
if (response) {
handleNotificationTap(response.notification);
}
});






This process is asynchronous. If you call router.push before verifying authentication or before the Navigator is ready, navigation can conflict. In my app, I run this after the login check completes.




CODE
useRegisterPushToken(authChecked);









Handling Notification Taps While Running



When a notification is tapped from either the background or foreground, the listener receives it.




CODE
const subscription =
Notifications.addNotificationResponseReceivedListener((response) => {
handleNotificationTap(response.notification);
});

return () => subscription.remove();






To avoid duplicate listeners from screen remounts or Fast Refresh, I call remove() in the cleanup.






Unifying Both Entry Points



Although the entry points differ, notification data validation and navigation are shared.




CODE
function handleNotificationTap(notification: Notifications.Notification) {
const data = notification.request.content.data as
| { url?: string; linkUrl?: string }
| null;

const raw = data?.url ?? data?.linkUrl;
if (!raw) return;

const path = raw.startsWith("/")
? raw
: (raw.match(/^https?:\/\/[^/]+(\/.+)$/)?.[1] ?? null);

if (!path) return;
router.push(path as never);
}






For backward compatibility with previously sent notifications, I accept both url and linkUrl. For new implementations, using a single key is simpler.



Also, passing externally provided URLs directly to router.push is less safe. I define allowed hosts and path formats, converting them to app-internal routes before passing.






Not Navigating on Received Notification



addNotificationReceivedListener and addNotificationResponseReceivedListener serve different purposes.




CODE
Notifications.addNotificationReceivedListener((notification) => {
// When notification is received
});

Notifications.addNotificationResponseReceivedListener((response) => {
// When user taps the notification
});






Switching screens immediately when a notification arrives can disrupt the user's current screen, such as an input form. In my app, screen navigation happens only with the response after a tap.






Unified Hook



Simplifying the actual structure, it looks like this:




CODE
export function useNotificationNavigation(enabled: boolean) {
useEffect(() => {
if (!enabled) return;

let active = true;

void Notifications.getLastNotificationResponseAsync().then((response) => {
if (active && response) {
handleNotificationTap(response.notification);
}
});

const subscription =
Notifications.addNotificationResponseReceivedListener((response) => {
handleNotificationTap(response.notification);
});

return () => {
active = false;
subscription.remove();
};
}, [enabled]);
}






Rather than treating launches from the terminated state and taps while running as the same thing, separating the entry points and then passing them to a common navigation function made the structure easier to maintain.






References





Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Debian 11 Long Term Support reaches end-of-life
1 Quelle
Updated Debian 13: 13.7 released
1 Quelle
USN-8741-1: Flatpak vulnerabilities