【问题标题】:Playing a custom sound on receiving a remote push notification on iOS 12 from FCM在 iOS 12 上从 FCM 接收远程推送通知时播放自定义声音
【发布时间】:2019-09-02 05:09:30
【问题描述】:

我正在尝试在应用程序完全关闭或在后台收到 REMOTE 通知时播放自定义声音,但我尝试过的所有操作均无效。 p>

我使用的音频文件是一个受支持的 .caf 文件,长度为 20 秒,在苹果的限制范围内。该文件位于主应用程序包中,而不是在特定方案中。我的远程通知注册是用.Sound注册的。

这是我的 XCode 项目管理器的屏幕截图,显示了我的自定义声音所在的位置。

从 firebase 函数发送远程通知的代码:

userData.tokens.forEach(async token => {
    console.log("Token: "+token);
    const message = {
        data: {
            type: "type"
        },
        android: {
            priority: "high"
        },                  
        notification: {
            "title": "Title of message",
            "sound": "customSound.caf"
        },
        apns: {
            headers: {
                "apns-priority": "10"
            },
            payload: {
                aps: {
                    sound: "customSound.caf"
                },
                    sound: "customSound.caf"
                }
            },
            token: token
        };
    console.log(message);
    await admin.messaging().send(message);
});

这是我的注册码在我的 AppDelegate 中的样子:

if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
    UNUserNotificationCenter.current().delegate = self
    Messaging.messaging().delegate = self
} else {
    let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
    application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()

我什至尝试重新启动我的设备,因为这是我在另一个 Stack Overflow 上读到的错误,但没有任何作用。如果有帮助,我将在第 6 代 iPad 上运行 iOS 12.1.4。

感谢您的任何建议。

编辑 忘了,我的 info.plist 文件里也有这个

<key>UILocalNotificationDefaultSoundName</key>
    <string>OnceAgainNotification.caf</string>  

【问题讨论】:

    标签: ios swift firebase apple-push-notifications


    【解决方案1】:

    您通过 firebase 发送的声音名称必须与声音文件的名称及其扩展名相匹配。

    此外,请确保从构建阶段开始在项目中正确实施文件。

    关于默认声音,iOS 10 后不推荐通过 info.plist 更改默认声音名称。

    https://developer.apple.com/documentation/uikit/uilocalnotificationdefaultsoundname

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      相关资源
      最近更新 更多