[ANDROID] registerNotificationReceivedBackground is not triggered when the app is killed.
Notifications.events().registerNotificationReceivedBackground() is triggered when the app is in the foreground and in the background but not when the app is killed.
'react-native': 0.61
'react-native-notificiations': 3.1.2
When App is killed you need to obtain the payload with this:
async componentDidMount() {
const notification: Notification = await Notifications.getInitialNotification()
console.log('initial', notification)
}
@siliconsocket Thanks for the quick reply!
How do you trigger the app to wake up and start processing the notification? Adding that line of code does not seem to be doing anything.
From the libary, PushNotification.java I see that onReceived() is triggered when a notification comes in while the app is killed. However, I can't seem to figure out how to get my app to start processing the notification and wake up to display the notification :/
@siliconsocket how do you trigger the app to wake up and start processing the notification?
I just received the push notification even when app is killed, then tap on it and app starts again and I recover the payload with componentDidMount() method in my main component.
I see. I don't receive push notifications when the app is killed, and only when the app is killed.
When App is killed you need to obtain the payload with this:
async componentDidMount() { const notification: Notification = await Notifications.getInitialNotification() console.log('initial', notification) }
In my case notification object was always thrown undefined... 😢😢😢😢
My Code
useEffect(()=>{
Notifications.getInitialNotification().then(notification=>{
console.log(notification);
}).catch(error=>{
console.log(error);
});
},[]);
When App is killed you need to obtain the payload with this:
async componentDidMount() { const notification: Notification = await Notifications.getInitialNotification() console.log('initial', notification) }In my case notification object was always thrown
undefined... 😢😢😢😢My Code
useEffect(()=>{ Notifications.getInitialNotification().then(notification=>{ console.log(notification); }).catch(error=>{ console.log(error); }); },[]);
I solved this problem !
don't call getInitialNoitification() function in useEffect()
You must be called to componentDidMount() check up react-native app lifecycle.
How did you resolve this issue @ldh1428a ? I have the same, getInitialNotitication always resolves me to undefined.. no matter if i call it from componentDidMount
How did you resolve this issue @ldh1428a ? I have the same, getInitialNotitication always resolves me to undefined.. no matter if i call it from componentDidMount
I same result undefined if app was been killed..
Application was background state getInitialNotification() return notification data, but app was dead(killed) state always return to undefined... 😢
Any solutions ? I always get undefined too from getInitialNotification(); and registerNotificationOpened(),registerNotificationReceivedForeground() did not trigger when it is called I have no idea what to do now. I'm using the latest version.
@alexbuicescu you did great job regarding channels in Android, may be you can help us with this problem?
I also can't get something from getInitialNotification() when app in dead(killed) mode.
Hi, from my knowledge, you can't process normal notifications while the app is killed. For that you need to send silent notifications (or data notifications, they are the same thing). Also, at the moment react-native-notifications does not support this. I use react-native-firebase for this.
Regarding the getInitialNotification, I'm not sure how to debug this issue, but I can look into it. It also bothers me that this is not working.
@alexbuicescu thank you for the quick response! Did I understand you right that for the particular case when app is killed/dead you are using react-native-firebase and this library for others?
Exactly
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
The issue has been closed for inactivity.
is this issue resolved?
@alexbuicescu I'm trying to use @react-native-firebase alongside this library to handle notifs when the app is killed (as you mentioned you did). I've noticed that when I install @react-native-firebase it doesn't allow react-native-notifications to handle the notifications, because only one "com.google.firebase.MESSAGING_EVENT" service will get triggered and it essentially stops at the @react-native-firebase project. How did you get around this? Did you have to implement something like this?
@ryanmcclure4, did you ever find a solution to this problem? I need to be able to have the app launched from a notification in Android too.