react-native-fcm
react-native-fcm copied to clipboard
Action click push notifocation
I can't get action click push notification. I want get action click because after click will open url . Thank you.
My code.
` componentDidMount() { //console.log('wrapper did mount') NetInfo.addEventListener('change', this._handleConnectionInfoChange ); NetInfo.fetch().done ( (connectionInfo) => { this._handleConnectionInfoChange(connectionInfo); } );
//Config Push Notification
if(Platform.OS == 'ios') {
FCM.requestPermissions()
.then(e => {})
.catch(() => {})
}
FCM.getFCMToken().then(token => {
// console.log('token', token)
if(token && token != undefined) {
this._saveDeviceToken(token)
}
})
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {
// console.log('token refresh', token)
if(token && token != undefined) {
this._saveDeviceToken(token)
}
})
FCM.getInitialNotification().then(notification => {
if(notification && notification.opened_from_tray) {
this._openUrl(this.state.url);
}
});
this.notificationListener = FCM.on(FCMEvent.Notification, (notification) => {
if(notification)
{
const url_open = notification.url;
this.setState({
url: url_open ? url_open : false
})
if(notification.local_notification) {
if(notification.opened_from_tray) {
this._openUrl(this.state.url);
}
return;
}
if(notification.opened_from_tray) {
return;
}
const title = notification.fcm.title;
FCM.presentLocalNotification({
priority: 'high',
title: title ? title : Params.Name,
body: notification.fcm.body,
big_text: notification.fcm.body,
icon: 'pushicon',
large_icon: 'joinmunch',
url : url_open,
lights: true,
show_in_foreground: true,
local: true
})
FCM.cancelAllLocalNotifications()
}
})
}`
this.setState({ url: url_open ? url_open : false }) sets states in next event loop. that might be your issue?
Does the callback get called?
When get notification i save url. I want get action click notification.
sorry I don't quite understand what you want
When you get a notification, when you touch it, it will open the app for you. I want to catch the event when you touch it. Previously, I could use get action to click. But current i can't.
FCM.getInitialNotification().then(notification => { if(notification && notification.opened_from_tray) { this._openUrl(this.state.url); } });
why currently you can't? someone opened an issue that notification.opened_from_tray is undefined in getInitialNotification
Previously after touch notification it will go to getInitialNotification. Current i don't see.
My Code
componentDidMount() { //console.log('wrapper did mount') NetInfo.addEventListener('change', this._handleConnectionInfoChange ); NetInfo.fetch().done ( (connectionInfo) => { this._handleConnectionInfoChange(connectionInfo); } );
//Config Push Notification
if(Platform.OS == 'ios') {
FCM.requestPermissions()
.then(e => {})
.catch(() => {})
}
FCM.getFCMToken().then(token => {
if(token && token != undefined) {
this._saveDeviceToken(token)
}
})
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {
if(token && token != undefined) {
this._saveDeviceToken(token)
}
})
FCM.getInitialNotification().then(notification => {
if(notification && notification.opened_from_tray) {
this._openUrl(this.state.url);
}
});
this.notificationListener = FCM.on(FCMEvent.Notification, (notification) => {
if(notification)
{
const url_open = notification.url;
this.setState({
url: url_open ? url_open : false
})
if(notification.local_notification) {
if(notification.opened_from_tray) {
this._openUrl(this.state.url);
}
return;
}
if(notification.opened_from_tray) {
return;
}
const title = notification.fcm.title;
FCM.presentLocalNotification({
priority: 'high',
title: title ? title : Params.Name,
body: notification.fcm.body,
big_text: notification.fcm.body,
icon: 'pushicon',
large_icon: 'joinmunch',
url : url_open,
lights: true,
show_in_foreground: true,
local: true
})
FCM.cancelAllLocalNotifications()
}
})
}
I haven't changed any behavior recently. don't you see it in FCM.on(FCMEvent.Notification?
yes. when click i don't see any one event in FCM.on(FCMEvent.Notification
so you are saying when you tap on notification you don't see any callback in javascript? How about moving the listeners out of component lifecycle?
Previously my code same now. It still working when tab on notification but current it not wroking.
Hi @evollu, I'm having the same problem. When notification received, I can log it from notification listener. When I click the notification,it show FCM without any other data

Any idea to solve this issue?
@dashracer let me check
wait. what OS are you using? iOS?
Can't do much for iOS and that's all the system gives me. Duplicated the value in data
@evollu Those screenshot from android
I don't have such issue with the example project in android

I am also facing the same issue as @ChanhTran255. I didn't get the data when i click on notification.
I also want an event when notification is clicked. I want to navigate to particular screen when notification is pressed. Any Solution?