【问题标题】:Not receiving fcm message when app is close in Android with react-native-firebase使用 react-native-firebase 在 Android 中关闭应用程序时未收到 fcm 消息
【发布时间】:2019-04-22 18:01:37
【问题描述】:

我按照here提到的步骤进行操作。

现在,当应用程序处于前台时,我通过 firebase.messaging().onMessage 接收消息,而在后台,通过我根据同一指南定义的无头任务接收消息,但是当应用程序处于前台时,我没有收到消息应用已关闭

我正在使用一加 6,我什至禁用了我手机的电池优化选项,尝试安装签名版本,但都不起作用。

这是我的bgMessaging.js

import firebase from 'react-native-firebase';
// Optional flow type
import type { RemoteMessage } from 'react-native-firebase';

export default async (message: RemoteMessage) => {

    const channel = new firebase.notifications.Android.Channel('channel-id', 'channel-Name', firebase.notifications.Android.Importance.Max)
    .setDescription('Description');
    firebase.notifications().android.createChannel(channel);

    const localNotification = new firebase.notifications.Notification()
    .setNotificationId(message.messageId)
    .setTitle("Title")
    .setSubtitle('Test')
    .setBody("Body")
    .setData(message.data)
    .android.setChannelId('channel-id')
    .android.setAutoCancel(false)
    .android.setPriority(firebase.notifications.Android.Priority.High);

  firebase.notifications().displayNotification(localNotification);

    return Promise.resolve();
}

甚至在 AndroidManifest.xml 中添加了这个

<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />

我在本机方面遗漏了什么吗?

【问题讨论】:

    标签: react-native react-native-android react-native-firebase


    【解决方案1】:

    您可以转到http://pushtry.com/ 并将json设置为:

    {
     "to":FCM_TOKEN
     "notification": {
        "body": "body",
        "title": "title"
        },
     "priority":'high'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-11
      • 2018-04-08
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      相关资源
      最近更新 更多