rn Notifee和Firebase在iOS中没有声音并显示徽章号

发布于 2025-01-23 06:23:37 字数 1245 浏览 0 评论 0 原文

我正在与React Anitial一起工作,当应用程序为背景时,iOS中会出现徽章数量和声音,但这是不起作用的,我正在使用Notifee和Firebase,当应用程序前景良好时,问题是何时是背景。

messaging().onMessage(async remoteMessage => {
      const channelId = await notifee.createChannel({
        id: 'default',
        name: 'Default Channel',
      });
      await notifee.displayNotification({
        title: remoteMessage.data?.title || '',
        body: remoteMessage.data?.message || '',
        data: {
          title: remoteMessage.data?.title || '',
          message: remoteMessage.data?.message || '',
          type: remoteMessage.data?.type || '',
        },
        android: {
          channelId,
          importance: AndroidImportance.HIGH,
          color: LightTheme.colors.primary,
          smallIcon: 'notification_icon',
          largeIcon: 'notification_icon',
          pressAction: {
            id: 'stop',
          },
        },
        ios: {
          badgeCount: 1,
          sound: 'default',
          foregroundPresentationOptions: {
            alert: true,
            badge: true,
            sound: true,
          },
        },
      });
    }); 

 messaging().setBackgroundMessageHandler(async () => {
      await notifee.incrementBadgeCount();
    });

I'm working with react native a need that appears the badge numbers and sound in iOS when the app is background but that is not working, I'm using notifee and firebase, when app is foreground working good the problem is when is background.

messaging().onMessage(async remoteMessage => {
      const channelId = await notifee.createChannel({
        id: 'default',
        name: 'Default Channel',
      });
      await notifee.displayNotification({
        title: remoteMessage.data?.title || '',
        body: remoteMessage.data?.message || '',
        data: {
          title: remoteMessage.data?.title || '',
          message: remoteMessage.data?.message || '',
          type: remoteMessage.data?.type || '',
        },
        android: {
          channelId,
          importance: AndroidImportance.HIGH,
          color: LightTheme.colors.primary,
          smallIcon: 'notification_icon',
          largeIcon: 'notification_icon',
          pressAction: {
            id: 'stop',
          },
        },
        ios: {
          badgeCount: 1,
          sound: 'default',
          foregroundPresentationOptions: {
            alert: true,
            badge: true,
            sound: true,
          },
        },
      });
    }); 

 messaging().setBackgroundMessageHandler(async () => {
      await notifee.incrementBadgeCount();
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2025-01-30 06:23:37

由于推送通知是由iOS处理的,而不是您的应用程序,因此您无法更改收到推送通知的应用徽章。
但是,您可以在推送通知的有效载荷中发送徽章编号,该徽章将适用于App图标,但为此,您必须执行计算服务器端。
You should read Local and Push Notification Programming Guide and especially the 

// Payload for remote Notification to APN
{
    "aps": {
        "content-available": 1,
        "alert": "Hallo, this is a Test.",
        "badge": 2, // This is your Int which will appear as badge number,
        "sound": default
    }
}

声音:默认值
将播放用于通知的自定义声音的默认声音
您应该将声音文件放在Android/App/res/raw中,对于iOS,您应该将声音文件放在AppName.xcodeproj文件中的资源中
现在,应用程序徽章图标将在应用程序图标上显示2个徽章。并播放您的自定义声音

Since push notification are handled by iOS and not your app you can't change the application badge on receiving a push notification.
But you can send the badge number in the payload of the push notification, which will be apply to app icon but for this you will have to do the calculation server side.
You should read Local and Push Notification Programming Guide and especially the The Notification Payload.
The payload could look like this:

// Payload for remote Notification to APN
{
    "aps": {
        "content-available": 1,
        "alert": "Hallo, this is a Test.",
        "badge": 2, // This is your Int which will appear as badge number,
        "sound": default
    }
}

Sound : default
will play the default sound 
for custom sound for notification
You should place your sound file in android/app/res/raw and 
for iOS you should place your sound file in Resource in appname.xcodeproj file
Now the app application badge icon will show 2 badge count on app icon . And play your custom sound

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文