简体   繁体   English

使用GCM的iOS自定义推送通知声音

[英]iOS custom push notification sounds using GCM

I am trying to play a custom sound when receiving a push notification to my iOS app. 收到我的iOS应用程序的推送通知时,我试图播放自定义声音。 I am using GCM on my server to push to Android and Apple devices. 我在服务器上使用GCM推送到Android和Apple设备。

By defaults I was sending the following in my push notification payload: "sound":"default". 默认情况下,我在推送通知有效负载中发送以下内容:“ sound”:“ default”。 This was working no problems, 100%. 这没有问题,100%。

As soon as I changed it to: "sound":"sound.wav" I was no longer receiving the "sound" tag in my payload in the debugger and naturally no sound was playing when the device received the payload. 一旦将其更改为:“ sound”:“ sound.wav”,我就不再在调试器的有效负载中接收到“ sound”标签,并且当设备接收到有效负载时,自然也没有声音在播放。

Obviously I have added sound.wav to my bundle and checked it in the bundle resources. 显然,我已经将sound.wav添加到我的捆绑软件中,并在捆绑软件资源中对其进行了检查。

Can anybody shed some light on this problem? 有人可以阐明这个问题吗?

There are few things which can cause this. 几乎没有什么可以导致此。

  1. The sound file "sound.wav" should be a second long and limited size in KBs. 声音文件“ sound.wav”应为第二个较长且大小受限制的KB文件。
  2. Make sure your payload is like this: 确保您的有效载荷是这样的:
 { "title": "Some title", "data": [ { "version": "1.0" } ], "aps": { "badge": 1, "sound": "soundfilenameinbundle.wav", "alert": "Some Alert to Show" } } 

Please make sure "sound" tag goes in "aps". 请确保“声音”标签放入“ aps”中。

  1. As you have said you have added the sound file, can you also check if it is added in the required target. 就像您说的那样,您已经添加了声音文件,还可以检查是否已将其添加到所需的目标中。

  2. Sometimes big sized payloads also cause this. 有时,大型有效载荷也会导致这种情况。 Try by reducing your payload size by removing some data for testing and check 尝试通过删除一些数据进行测试和检查来减小有效负载大小

  3. As you said you cannot see "sound" tag in the payload. 如您所说,您无法在有效负载中看到“声音”标签。 I suspect the problem in payload itself. 我怀疑有效载荷本身存在问题。 Can you try changing file name. 您可以尝试更改文件名吗?

Also try on iOS 7/8/9 to check if the problem is not OS specific. 另外,请尝试在iOS 7/8/9上检查问题是否与操作系统无关。

I hope this will help. 我希望这将有所帮助。

Thanks Suhail, 谢谢Suhail,

The problem is with Google Cloud Messaging. 问题出在Google Cloud Messaging。 They only support the "default" value for the sound tag. 它们仅支持声音标签的“默认”值。 So whenever I change it to anything but that the GCM server does not send the sound tag at all. 因此,只要我将其更改为其他任何内容,GCM服务器就不会发送声音标签。

Hope they fix it soon... 希望他们尽快解决...

Details here: https://developers.google.com/cloud-messaging/http-server-ref 此处的详细信息: https : //developers.google.com/cloud-messaging/http-server-ref

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

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