evollu / evollu/react-native-fcm

not open particular screen when user tap on notification banner

Open
#816 26 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.7k
Forks
661
PR merge metrics
No merged PRs in 30d

Description

Hello sir

I need Open particular screen when user tap on notification banner.

Following is my js code it 's perfectly work on ios not not in android

so plz help me

and also not getting payload in android but getting in ios

componentDidMount() {
this.notificationSetup()
}

async notificationSetup(){
await FCM.requestPermissions({badge: false, sound: true, alert: true}).then(()=>console.log('granted')).catch(()=>console.log('notification permission rejected'));

FCM.getFCMToken().then((token) => {
console.log("TOKEN (getFCMToken)", token);
AsyncStorage.setItem(APPCONSTANTS.ASYNCKEY.LOGIN.DEVICETOKEN,token+"")

if(_this.state.deviceTokenId != token){
if(_this.state.userId != null && _this.state.userId != undefined){
isOnline().then(online => {
if(online){
this.updateToken(token)
}
});
}else{
console.log("User Id Null")
}
}else{
console.log("Token id Matched")
}

//this.setState({deviceToken:token})
});

FCM.getInitialNotification().then(notif => {
console.log("INITIAL NOTIFICATION", notif)
});

this.notificationListner = FCM.on(FCMEvent.Notification, notif => {
console.log("Notification", JSON.stringify(notif));
if(notif.local_notification){
return;
}
if(notif.opened_from_tray){

// if (notif.cutom_action == '0' || notif.cutom_action == '1') {
// // setTimeout(() => {Actions.searchResult({notification : true ,jobId :1002})},500)
// // setTimeout(() => { Actions.sidemenu({ notification: true, allJobScreen: true }) }, 500)
// Actions.sidemenu({ notification: true, allJobScreen: true })
// } else if (notif.cutom_action == '2' || notif.cutom_action == '3') {
// // console.log("Activity screen")
// // setTimeout(() => { Actions.sidemenu({ notification: true, activityScreen: true }) }, 500)
// Actions.sidemenu({ notification: true, activityScreen: true })
// } else {
// // console.log("custom")
// // setTimeout(() => { Actions.sidemenu({ notification: true }) }, 500)
// Actions.sidemenu({ notification: true })
// }

if (notif.custom_notification.cutom_action == '0' || notif.custom_notification.cutom_action == '1') {
// setTimeout(() => {Actions.searchResult({notification : true ,jobId :1002})},500)
// setTimeout(() => { Actions.sidemenu({ notification: true, allJobScreen: true }) }, 500)
Actions.sidemenu({ notification: true, allJobScreen: true })
} else if (notif.custom_notification.cutom_action == '2' || notif.custom_notification.cutom_action == '3') {
// console.log("Activity screen")
// setTimeout(() => { Actions.sidemenu({ notification: true, activityScreen: true }) }, 500)
Actions.sidemenu({ notification: true, activityScreen: true })
} else {
// console.log("custom")
// setTimeout(() => { Actions.sidemenu({ notification: true }) }, 500)
Actions.sidemenu({ notification: true })
}

}

if (Platform.OS == 'ios') {

//optional
//iOS requires developers to call completionHandler to end notification process. If you do not call it your background remote notifications could be throttled, to read more about it see the above documentation link.
//This library handles it for you automatically with default behavior (for remote notification, finish with NoData; for WillPresent, finish depend on "show_in_foreground"). However if you want to return different result, follow the following code to override
//notif._notificationType is available for iOS platfrom
switch (notif._notificationType) {
case NotificationType.Remote:
notif.finish(RemoteNotificationResult.NewData) //other types available: RemoteNotificationResult.NewData, RemoteNotificationResult.ResultFailed
break;
case NotificationType.NotificationResponse:
notif.finish();
break;
case NotificationType.WillPresent:
notif.finish(WillPresentNotificationResult.All) //other types available: WillPresentNotificationResult.None
break;
}
}
this.showLocalNotification(notif);
});

this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, token => {
AsyncStorage.setItem(APPCONSTANTS.ASYNCKEY.LOGIN.DEVICETOKEN,token+"")
console.log("TOKEN (refreshUnsubscribe)", token);
if(_this.state.deviceTokenId != token){
if(_this.state.userId != null && _this.state.userId != undefined){
isOnline().then(online => {
if(online){
this.updateToken(token)
}
});
}else{
console.log("User Id Null")
}
}else{
console.log("Token id Matched")
}
});
}

showLocalNotification(notif) {

console.log("Push Notification Data-->"+JSON.stringify(notif))

// var customeData = JSON.parse(notif.body);

// console.log("Custom Data-->"+JSON.stringify(customeData));
FCM.presentLocalNotification({
vibrate: notif.vibrate,
title: notif.title,
body: notif.body,
priority: "high",
sound: notif.sound,
show_in_foreground: true,
});

}

componentWillUnmount() {
this.notificationListner.remove();
this.refreshTokenListener.remove();
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.