如何在React Native中创建Firebase推送通知组?

ecbunoof  于 2022-12-14  发布在  React
关注(0)|答案(1)|浏览(148)

我在React Native中使用Firebase创建推送通知组时遇到问题,当我收到许多推送通知时,我想将其创建为1个组,如WhatsApp(如下图中的红色圆圈)。

我试着找了很多例子,但我没有找到一个解决方案。请任何人帮助我创造这样的。

  • 谢谢-谢谢
dba5bblo

dba5bblo1#

使用react-native-push-notification
//创建通道

import PushNotification, {Importance} from 'react-native-push-notification';
...
  PushNotification.createChannel(
    {
      channelId: "channel-id", // (required)
      channelName: "My channel", // (required)
      channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
      playSound: false, // (optional) default: true
      soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
      importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
      vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
    },
    (created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
  );

//这会将每个新通知显示一段时间,然后将其推入组

PushNotification.localNotification({
      channelId: 'channel-id',
      title: `New message`,
      message: 'Hello world',
})

//此群组消息

PushNotification.localNotification({
      channelId: 'channel-id',
      id: 'messages',
      group: 'messages',
      groupSummary: true
})

相关问题