【问题标题】:Push notifications with custom sounds not showing up in iOS带有自定义声音的推送通知未在 iOS 中显示
【发布时间】:2019-09-14 08:19:28
【问题描述】:

使用 firebase 云功能完成的自定义推送通知在 android 上完美运行,但在 iOS 上不适用。

我已尝试将自定义声音放在 Runner 文件夹中,如在线多个教程中所见。它是一个 .wav 文件。

我的云功能负载设置如下:

var payload = {
            "notification": {
                "title": msgData.name +" Needs Your Help!",
                "body": "new Alert Message: "+msgData.job_type,
                "sound": "submarine.wav"
            },

在 android 上通知有效,但在 ios 上它甚至不显示通知。如果它把声音设为默认,它可以工作,但它根本不播放自定义的 subsub.wav 文件

【问题讨论】:

  • 您是否已将声音文件导入您的项目,确保它包含在捆绑包中并将其链接到正确的目标?
  • @BrandonStillitano 我已经完成了所有这些,但仍然无法正常工作。有没有其他方法可以做到这一点?
  • 我什至将文件转换为 .CAF 。我对此没有其他解决方案...

标签: javascript ios dart flutter firebase-cloud-messaging


【解决方案1】:

为 iOS 和 Android 配置消息时,您还必须设置应用程序设置。请参阅下面的指南。

https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#ApnsConfig

payload = {
    notification:{
        title: 'Notification title goes here',
        body: 'Body of notification goes here',
    },
    android: {
    },
    apns: {
        headers:{
            "apns-collapse-id": "id_here",
            "content-available": "1",
            "apns-priority": "10",
        },
        payload:{
            aps:{
                sound: 'default'
            }
        }
    },
    data:{
        type: 'type'
    }
}

【讨论】:

  • 我会试试这个,但它怎么能与默认声音完美配合呢?另外,apns-collapse-id 是应用 ID 吗?
  • 我找到了解决方案!一些我忘记检查权限的方式:_messaging.requestNotificationPermissions()
  • @SkyentGroup 不,它是将消息分组在一起的 Id。如果通知来自同一消息线程等,则很有用
  • 此解决方案不适用于云功能。这是他们显示的错误:Error: Messaging payload contains an invalid "apns" property. Valid properties are "data" and "notification".
猜你喜欢
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多