Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React Native-Android-FCM-Display组通知,如';s应用程序还允许多个分组通知_Android_React Native_Firebase Cloud Messaging - Fatal编程技术网

React Native-Android-FCM-Display组通知,如';s应用程序还允许多个分组通知

React Native-Android-FCM-Display组通知,如';s应用程序还允许多个分组通知,android,react-native,firebase-cloud-messaging,Android,React Native,Firebase Cloud Messaging,我想显示一个组通知,而不是像whatsapp那样显示多个通知。 例如: 一个通知,信息为“2讨论1评论”,而不是 共收到三份通知 我使用了本机fcm库() 我使用了组键和标记键,但无法实现如下代码所示的结果 FCM.presentLocalNotification({ title: 'Title', body: 'Body', priority: "high", click_action: true, show_in_foreground: true, local: tr

我想显示一个组通知,而不是像whatsapp那样显示多个通知。 例如: 一个通知,信息为“2讨论1评论”,而不是 共收到三份通知

我使用了本机fcm库() 我使用了组键和标记键,但无法实现如下代码所示的结果

FCM.presentLocalNotification({
  title: 'Title',
  body: 'Body',
  priority: "high",
  click_action: true,
  show_in_foreground: true,
  local: true,
  group: 'group1',
  tag: 'tag1'
});

是否可以在react native FCM中实现此功能?请让我知道。

项目react-native fcm移动到react-native firebase下,下面有一个解决方案

主要思想是:

诀窍是创建一个包含该组通知的附加通知


您是否使用安卓7.0或更高版本?较低版本不支持原因组。您可以在此处阅读如何在旧版本上实现相同的结果:
// ID for grouping notifications, always the same
const SUMMARY_ID = `${ALERTS_GROUP}.summary`

const sendIt = (notification: Firebase.notifications.Notification) => {
  return firebase.messaging().hasPermission().then((yes) => {
    if (yes) {
      try {
        return firebase.notifications().displayNotification(notification)
          .catch((err) => {
            Log.e(`[sendNotification] ERROR: ${err}`)
            return Promise.resolve()
          })
      } catch (err) {
        Log.e('[sendNotification] Error displaying notification: ' + err)
      }
    }
    return Promise.resolve()
  })
}

const sendSummary = (data: MessageData) => {
  const summary = new firebase.notifications.Notification()
    .setNotificationId(SUMMARY_ID)
    .setTitle(_T('notification.channels.alert.description'))
    .setData(data)
    .android.setAutoCancel(true)
    .android.setCategory(firebase.notifications.Android.Category.Message)
    .android.setChannelId(getChannelId(MsgType.Alert))
    .android.setColor(variables.scheme.primaryColor)
    .android.setSmallIcon(STATUS_ICON)
    .android.setGroup(ALERTS_GROUP)
    .android.setGroupSummary(true)
    .android.setGroupAlertBehaviour(firebase.notifications.Android.GroupAlert.Children)
  sendIt(summary)
}

/**
 * Called by `bgMessaging` or the `onMessage`  handler.
 */
export function sendNotification (message: Firebase.messaging.RemoteMessage) {
  const payload: MessagePayload = message.data as any || {}
  const notification = new firebase.notifications.Notification()
  // ... more code

  if (Platform.OS === 'android' && Platform.Version >= 24) {
    notification.android.setGroup(ALERTS_GROUP)
    sendSummary(notification.data)
  }
  Log.v('[sendSummary] sending notification.')
  return sendIt(notification)
}