wix / react-native-notifications

React Native Notifications
MIT License
3.25k stars 764 forks source link

Possible to set the initial notification when the app is being foregrounded? #918

Closed RyanSept closed 1 year ago

RyanSept commented 1 year ago

Currently if the app was already running but in the background and the user opens it via a push notification, getInitialNotification() returns undefined. Is it possible to set the initial notification to be available when the app is being foregrounded?

This was tested on Android 12

"react-native": "0.66.4",
"react-native-notifications": "4.3.2"
cheymonty commented 1 year ago

try all of these to see which gets called

Notifications.events().registerNotificationReceivedForeground((notification, completion) => {
      console.log(notification)
});
Notifications.events().registerNotificationReceivedBackground((notification, completion) => {
      console.log(notification)
});
Notifications.events().registerNotificationOpened((notification, completion) => {
      console.log(notification);
});
RyanSept commented 1 year ago

Thanks Cheyenne. I already have these callbacks registered, the problem is with the getInitialNotification() function

// User presses on a notification and it opens the app by launching it
Notifications.getInitialNotification(); -> Notification(...)

// User presses on a notification for a backgrounded app and it opens the app by foregrounding it
Notifications.getInitialNotification(); -> undefined

I think the second scenario should behave similarly to the first

blolo commented 1 year ago

@RyanSept did you manage to find a solution to thus issue?

RyanSept commented 1 year ago

@blolo I used AsyncStorage to store the notification upon registerNotificationOpened() then when the app rendered I have a callback that checks a notification is present in AsyncStorage and does actions on it.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] commented 1 year ago

The issue has been closed for inactivity.