react-native-firebase unable to handle notificatio

2019-07-11 14:05发布

i'm using this react-native-firebase and react-navigation for navigating and i can push notification from server or console successfully whether its in foreground or background but i swear the documentation is not pretty clear how to open notification and navigate to the notification screen it belongs to. these are my onMessage codes.

 firebase.messaging().onMessage((payload) => {

     if(!payload.opened_from_tray){
      firebase.messaging().createLocalNotification({
        title: payload.title,
        body: payload.body,
        show_in_foreground: true,
        icon: "ic_launcher",
        local_notification: "true",
        priority: "high",
        click_action:"ACTION",
        opened_from_tray: true,
      })
     }


  });

i'm running the version 3.2.2 of react-native-firebase

1条回答
▲ chillily
2楼-- · 2019-07-11 14:51

right now i am not using createLocalNotification(), so am able to receive a notification when my app is closed using getInitialNotification(), :)

firebase.messaging().getInitialNotification()
    .then(payload => {
      console.log(payload);
      if(payload.slug != undefined){
        this.props.navigation.navigate('notification',{slug:payload.slug});
      }else{

      }
    });

i hope it solves your issue too

查看更多
登录 后发表回答