Sahak Stepanyan
Sahak Stepanyan

Reputation: 31

Expo Push Notification Detection

how can i detect when coming notification and make some changes when app is closed...

I'm using expo-notifications https://docs.expo.io/versions/latest/sdk/notifications/

Upvotes: 3

Views: 1186

Answers (1)

Greg T
Greg T

Reputation: 3414

Your app is not notified when it is closed/backgrounded, until the user interacts with it.

From the Expo 38 release notes:

If the notification is triggered while the app is in background,

  • it’s presented immediately

  • the application is not informed of this

If the notification is triggered while the app is in foreground,

  • the application not only receives immediate information about this, but…

  • it can also decide at runtime whether to display a heads-up alert or play a sound! (For more information see the Notification Handler documentation.)

From the Notifications overview, there are 2 listeners:

addNotificationReceivedListener - This listener is fired whenever a notification is received while the app is foregrounded

addNotificationResponseReceivedListener - This listener is fired whenever a user taps on or interacts with a notification (works when app is foregrounded, backgrounded, or killed)

The Notifications SDK is a good reference as well.

Upvotes: 1

Related Questions