简体   繁体   English

无法“打开”应用在后台时收到的通知

[英]Cannot "open" notification that is received when the app is in background

i have a problem when i want to process notification that is received when the app is in the background.当我想处理应用程序在后台时收到的通知时,我遇到了问题。 I do receive the notification, when i click on the notification, the app opens however the FCM.on method is not executed at all, it seems it does not handle the callback.我确实收到了通知,当我点击通知时,应用程序打开但是 FCM.on 方法根本没有执行,它似乎不处理回调。

When the app is in the foreground everything is working fine, and it process the notification without any problems.当应用程序在前台时一切正常,并且它可以毫无问题地处理通知。

This is the code in react-native这是 react-native 中的代码

FCM.on(FCMEvent.Notification, notif => {
      switch(notif.fcm.action){
        case 'fcm.ACTION.HANDLEMESSAGE':
          var data = {
            thread: notif.pk,
            message: JSON.parse(notif.message)
          }

          this.props.dispatch(fcmMSG(data));
          this.props.dispatch(addNotification(notif.pk, notif.job_id));
          break;

        case "fcm.ACTION.HANDLEAPPLICATION":
          axios.get(newServerURL + "/jobs/companyJobDetails/" + notif.recruitJobId + "/")
              .then((response) => {
                  var jobMainRecruits = response.data;
                  const {navigator} = this.refs;
                  navigator.push({
                  jobMainRecruits,
                  });
            })
              .catch((error) => {
                  console.log("ERROR")
            });        
          break;

        default:
      }
    });  
FCM.getInitialNotification().then(notif => {
      switch(notif.fcm.action){
        case 'fcm.ACTION.HANDLEMESSAGE':

          const { navigator } = this.refs;

          var thread = {
            candidate: notif.candidate,
            company: notif.company,
            candidate_avatar: notif.candidate_avatar,
            candidate_first_name: notif.candidate_first_name,
            candidate_last_name: notif.candidate_last_name,

            job_id: notif.job_id,
            pk: notif.pk,
            subject: notif.subject,
            message: JSON.parse(notif.message)
          }

          navigator.push({
            thread,
          });

          break;
        case "fcm.ACTION.HANDLEAPPLICATION":
          axios.get(newServerURL + "/jobs/companyJobDetails/" + notif.recruitJobId + "/")
              .then((response) => {
                  var jobMainMessages = response.data;
                  const {navigator} = this.refs;
                  navigator.push({
                  jobMainMessages,
                  });
            })
              .catch((error) => {
                  console.log("ERROR")
            });          
          break;

        default:

      }
    })

EDIT: this is my code in the backend编辑:这是我在后端的代码

push_service = FCMNotification(api_key=FCM_API_KEY)
                    registration_id = token.token
                    message_title = jobInfo.title
                    message_body = "New application"
                    message_icon = 'ic_launcher'
                    sound = 'Default'
                    color = '#362F64'
                    click_action='fcm.ACTION.NEWJOBAPPLICATION'
                    data_message = {'recruitJobId': self.request.data['job'], 'message_title': message_title, 'message_body': message_body}
                    result = push_service.notify_single_device(click_action=click_action, registration_id=registration_id, message_title=message_title, message_body=message_body, message_icon=message_icon, sound=sound, data_message=data_message, color=color)

Thanks for help in advance.提前感谢您的帮助。

The initial notification contains the notification that launches the app.初始通知包含启动应用程序的通知。 If the user launches the app by clicking the banner, the banner notification info will be here rather than through FCM.on event.如果用户通过单击横幅启动应用程序,横幅通知信息将显示在此处,而不是通过 FCM.on 事件。 sometimes Android kills activity when the app goes to background, and then resume it broadcasts notification before JS is run.有时,当应用程序进入后台时,Android 会终止活动,然后在运行 JS 之前恢复它广播通知。 You can use FCM.getInitialNotification() to capture those missed events.您可以使用FCM.getInitialNotification()来捕获那些错过的事件。 source来源

FCM.getInitialNotification().then(notif => {
    // do some logic here
   // I usually add this function inside my root page
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到推送通知时打开Android应用 - Open Android App when Push Notification is received 当应用程序被终止或在后台收到 fcm 通知时自动打开应用程序 - open app automatically when fcm notification is received while app is kill or on background 应用程序在前台时收到的推送通知与应用程序在后台时收到的推送通知不同 - Push notification received while the app is in the foreground is different from push notification received when the app is in background 在后台应用程序时从通知中打开片段 - Open fragment from notification when the app in background 如何在应用程序在后台时收到的通知中保存数据 - How to save data from notification received when the app is in the background 当收到Firebase通知且应用程序在后台时显示对话框 - Show a Dialog when Firebase Notification is received and App is in the background Firebase 在 android 中从后台删除应用程序时未收到推送通知 - Firebase push notification not received when app remove from background in android 如何取消应用程序在后台运行时收到的通知? - how to cancel a notification that received when app run in the background? 如何在收到通知且应用程序处于后台时调用 android 中的另一个活动 - How to call another activity in android when notification received and app is in background 收到远程通知时,在后台运行该方法而不启动应用程序 - run the method in background without launching app when remote notification received
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM