rn Notifee和Firebase在iOS中没有声音并显示徽章号
我正在与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();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于推送通知是由iOS处理的,而不是您的应用程序,因此您无法更改收到推送通知的应用徽章。
但是,您可以在推送通知的有效载荷中发送徽章编号,该徽章将适用于App图标,但为此,您必须执行计算服务器端。
You should read Local and Push Notification Programming Guide and especially the
声音:默认值
将播放用于通知的自定义声音的默认声音
您应该将声音文件放在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:
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