简体   繁体   English

Firebase 推送通知自定义声音

[英]Firebase push notifications custom sound

I am currently working on an app and I have implement firebase Push Notification service into my app.我目前正在开发一个应用程序,并且我已经在我的应用程序中实现了 firebase 推送通知服务。 I am recieving notification on my iphone but I am unable to set the custom alert sound that I want.我在我的 iphone 上收到通知,但我无法设置我想要的自定义警报声音。

  • I added the sound as a .caf我将声音添加为 .caf<\/li>
  • I added the sound to the Copy Bundle Resources<\/code>我将声音添加到Copy Bundle Resources<\/code><\/li><\/ul>

    using print (userInfo)<\/code> I have collected this data that is incomming from Firebase使用print (userInfo)<\/code>我收集了这些来自 Firebase 的数据

    aps: { alert = { body = MSG; title = Title; }; sound = default;}, {...}, sound: alarm.caf<\/code><\/pre>

    I understand where the problem is, I just dont understand how to fix it so that the app plays my custom notification sound.我知道问题出在哪里,我只是不明白如何解决它,以便应用程序播放我的自定义通知声音。

    Firebase 通知控制台 IMG

    "

Problem with Firebase is that you can not send sound parameter like custom parameter with Firebase Console, if you try this as you do, you will get this parameter in app outside of aps Dictionary and the system will not recognize it as a sound to be played although the sound file is into the project. Firebase的问题在于您无法使用Firebase控制台发送自定义参数声音参数 ,如果您这样做,您将在aps字典之外的app中获取此参数,系统将无法将其识别为要播放的声音虽然声音文件是进入项目的。

The only solution for this problem is you have some API/server through which you'll be sent a Firebase notification. 此问题的唯一解决方案是您有一些API /服务器,通过它您将收到Firebase通知。 When server send you a notification with sound param it will be within aps Dictionary and application will play this sound when the notification arrives. 当服务器向您发送带声音参数的通知时,它将在aps字典中,并且应用程序将在通知到达时播放此声音。

After much research I have not found any solution. 经过大量研究后,我没有找到任何解决方案。 Under Firebase Messaging Docs , and Firebase Messaging文档下 ,和

Table 2a. 表2a。 iOS — keys for notification messages iOS - 通知消息的密钥

it is indicated that Firebase does allow for the Sound key to be included in the payload but as seen in the code printed by didRecieveRemoteNotification , 表明Firebase允许将Sound键包含在有效负载中,但是在didRecieveRemoteNotification打印的代码中可以看到,

aps: {
alert =     {
    body = MSG;
    title = Title;
};
sound = default;}, {...}, sound: alarm.caf

Firebase doesn't include the Sound key inside the aps hence not calling the sound key by the app. Firebase不包含aps的声音键,因此不会通过应用程序调用声音键。

The workaround that I used for my app is Easy APNs Provider which is a handy and easy app to use for development purposes, a major issue is that it doesn't have the ability to register and remove notifications automatically. 我用于我的应用程序的解决方法是Easy APNs Provider ,它是一个方便易用的应用程序,用于开发目的,一个主要问题是它无法自动注册和删除通知。

lastly: for Push Notifications to my published apps, I have opted for a dedicated server which I run off of my website 最后:对于我发布的应用程序的推送通知,我选择了一个专门的服务器,我运行我的网站

It's been over 5 years, but if someone still looking for an answer, here is what I did.已经 5 年多了,但如果有人仍在寻找答案,这就是我所做的。

  1. Make sure you have configured Firebase Messaging & receiving Notifications.确保您已配置 Firebase 消息传递和接收通知。

  2. Add .caf ( sound file ) to the app.将 .caf(声音文件)添加到应用程序。 It must be visible on 'Target' - > 'Build Phases' & then under 'Copy Bundle Resources'它必须在“目标”->“构建阶段”上可见,然后在“复制捆绑资源”下

在此处输入图像描述

  1. Delete the app from the device ( This is important )从设备中删除应用程序(这很重要)

  2. I use Postman as my server, so message format would be,我使用 Postman 作为我的服务器,所以消息格式是,

     { "notification": { "title": "Hello", "sound":"small_message.caf", "body": "You have a new Job" }, "to": "your device token" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM