首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-native-fcm如何在点击托盘通知后重定向到特定页面

react-native-fcm如何在点击托盘通知后重定向到特定页面
EN

Stack Overflow用户
提问于 2017-08-25 12:09:44
回答 1查看 1.9K关注 0票数 0

在react-native-fcm中点击任务栏中的通知后,我正在尝试重定向到特定页面,但无法执行此操作。React原生fcm文档没有关于处理单击侦听器的适当文档

I follow this tutorial for react-native-fcm

代码语言:javascript
复制
 this.notificationListener = FCM.on(FCMEvent.Notification, notif => {
  console.log("Notification recived", notif);
  if(notif.local_notification){
     console.log("Notification recived local", "local notification");

    return;
  }
  if(notif.opened_from_tray){

     console.log("Notification recived tray ", "opened from tray");

    return;
  }

  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;
          }
  }

任何帮助都将不胜感激。

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-28 22:42:47

大家好,问题是通过在通知opened_from_tray块中使用setTimeout函数来修复的。

示例代码

代码语言:javascript
复制
redirect(){ this.props.navigator.push({name:"DetailPage", data:this.state.pageData[1]}); }

`

this.notificationListener = FCM.on(FCMEvent.Notification, notif => {
console.log("Notification recived", notif);
if(notif.local_notification){
console.log("Notification recived local", "local notification");

  if(notif.opened_from_tray){

     console.log("Notification recived local ", "opened from tray");

    setTimeout(() => {

    //    console.log('setting page call!'); 
    console.log('this is props',props);
      this.redirect()
      // this.props.navigator.push({name:"Sports"});
    //  // this.props.navigator.push({name:'DetailPage',data:Data});
    }, 5000);

     //this.props.navigator.push({name:"Settings"});

  }

return;
}
if(notif.opened_from_tray){

 console.log("Notification recived tray ", "opened from tray");
 //this.props.navigator.replacePrevious({name:"Settings"});
return;
}

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;
}
}`
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45874318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档