When APP run both in foreground and background,
I know notification is clicked in onNotification.
When I kill APP first and click notification, APP start running but onNotification is not triggered.
Is there method getting the notification clicked event?
See my https://github.com/zo0r/react-native-push-notification/issues/319#issuecomment-297067645. Have you the same issue?
I think you're looking for popInitialNotification eg:
componentWillMount() {
PushNotification.popInitialNotification(notification => {
handleColdNotification(notification);
})
}
@systemride, thanks, i'm already found the solution, but it's a bug in library.
@valeryq, yap, I have the same issue.
I have tried popInitialNotification, seems still not work.
@valeryq can you tell me how you solved this? If it is a bug in library, could you submit a PR?
Has anyone found a solution to this? Really need to get this working my side:/ @valeryq what was your solution?
@shrutic @JonoH hello guys. You must manually invoke the PushNotification.popInitialNotification(notification => YOU_HANDLER(notification)) each time when application started. For example in your root component in componentDidMount.
In my case, I invoking popInitialNotification one time, when application state is changed to active and remove listener for this event.
Example:
const appStateListener = (state) => {
if (state === 'active') {
AppState.removeEventListener('change', appStateListener);
PushNotification.popInitialNotification(notification => notification && onNotification(notification));
}
};
AppState.addEventListener('change', appStateListener);
@valeryq that works!!! Thanks so much! I'm now receiving the notification in the onNotification handler once I click on the notification (regardless of app state). Lifesaver!!
This needs to make it into the documentation as many people seem to be struggling with this exact issue.
I tried this but it didn't work for me. I eventually handled it in my iOS and android native code
Shruti
Sent from my iPhone
On Jul 25, 2017, at 1:53 AM, Jonathan Hatting notifications@github.com wrote:
@valeryq that works!!! Thanks so much! I'm now receiving the notification in the onNotification handler once I click on the notification (regardless of app state). Lifesaver!!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
@valeryq wow thank you! I was pulling my hair out over this.
For anyone coming upon this who might be having the same issue:
My onNotification would work fine when the app was coming from a cold start (not just backgrounded). But when the app was only backgrounded and not closed, the initial notification would not be popped and handled until the next cold start. Adding an app state listener and calling popInitialNotification would handle the case where the app was backgrounded.
An important note:
Notification data will be returned as a string in the popInitialNotification callback. This is because onNotification checks if it's a string and parses it behind the scenes, as seen here: https://github.com/zo0r/react-native-push-notification/blob/master/index.js#L233
This feels like a bug in the library to me, but it's pretty simple to just implement that check in the popInitialNotification callback.
On clicking notification I am able to get call inside
PushNotification.popInitialNotification(notification) but the notification data is null, I need to route user to different screens based on the notification data.
Could any one please help.
Here is my function, the notification field is printed as null.
PushNotification.popInitialNotification(notification => this.handleNotification(notification));
handleNotification(notification) {
console.log("The notification is----->", notification);
}
@csooraj did you solve the issue ?
@Clcll I could'nt solve the issue so I used react-native-fcm
any update on this? if you can't add actions to your notifications then it doesn't make sense to use this package, no?
@valeryq thanks for an interesting solution, but for me notification is always null :( And also it is called all time when the app is opened even not from notification...
Can you please help?
@valeryq thanks for an interesting solution, but for me notification is always null :(
Can you please help?
Hi, sorry, but I'm already out of context. 2 years have already passed...
Thanks for a quick response @valeryq
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.
Most helpful comment
@shrutic @JonoH hello guys. You must manually invoke the
PushNotification.popInitialNotification(notification => YOU_HANDLER(notification))each time when application started. For example in your root component incomponentDidMount.In my case, I invoking popInitialNotification one time, when application state is changed to
activeand remove listener for this event.Example: