简体   繁体   English

无法使用“ node fcm-notification”显示FCM通知

[英]Unable to display FCM notification using 'node fcm-notification'

I am working on a video calling app where a user gets notified via a notification when there is an incoming call and be able to click on the notification to start the call. 我正在开发一个视频通话应用程序,在该应用程序中,当有来电时,用户会通过通知收到通知,并且可以单击通知来开始通话。 Right now, the notification gets pushed when the app is closed or is running in the background, but doesn't when the app is opened in foreground. 现在,当应用程序关闭或在后台运行时,通知会被推送,但当应用程序在前台打开时,通知不会推送。

Also, clicking on the notification when the app is in background or not running will only open the app and not start the video call. 另外,当应用程序处于后台或未运行状态时,单击通知只会打开该应用程序,而不会发起视频通话。 The only way I can start the call is by receiving a notification when the app is in background / not running, manually opening the application and then clicking on the notification. 我可以启动呼叫的唯一方法是在应用程序处于后台/未运行状态时收到通知,手动打开该应用程序,然后单击该通知。

Here is my code that handles the notification sending: 这是我处理通知发送的代码:

var fcm = require('fcm-notification');
var serverKey = require('./fcmKey.json');
var FCM = new fcm(serverKey);

const payloadBody = {
     room,
     caller,
     language,
     receiver
}

var message = {
     token : deviceToken,
     data : payloadBody,
     notificaton: {
         title : 'MyApp',
         body: 'Somebody is calling'
}

FCM.send(message, function(err, response) {
    if(err) {
        console.error('Notification error: ${JSON.stringify(err)}');
    } else {
        console.error('Notification success: ${JSON.stringify(response)}');
    }
}

My manifest also contains the fcm service like this: 我的清单还包含fcm服务,如下所示:

<service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
  <intent-filter>
      <action android:name="com.google.firebase.MESSAGING_EVENT"/>
  </intent-filter>
</service>

What you're describing with respect to foreground and background behavior is exactly how notification type messages are supposed to work . 关于前台和后台行为,您所描述的正是通知类型消息应该如何工作 If you want to take control over the behavior of the notification that gets displayed to the user, you should remove the notification payload from the message, and build the whole thing yourself in response to the data payload . 如果要控制显示给用户的通知的行为,则应从消息中删除通知有效负载,并根据数据有效负载自己构建整个对象。 You'll receive that message in a FirebaseMessagingService subclass that you create. 您将在创建的FirebaseMessagingService子类中收到该消息

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM