如何使用Apple推送通知获得自定义声音? [英] How can I get a custom sound to play with an Apple Push Notification?

查看:154
本文介绍了如何使用Apple推送通知获得自定义声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Apple推送通知发送时播放自定义声音。弹出消息显示,徽章也会更新,但我总是会播放默认的iPhone声音,而不是我的自定义声音。

I am trying to get a custom sound to play when my Apple push notification is delivered. The popup message displays, and the badge updates too, but I always get the default iPhone sound playing instead of my custom sound.

这是我发送的JSON数据:

Here's the JSON data I am sending:


{aps:{sound:sound.caf,badge:2,alert:已成功注册设备}}

{"aps": {"sound": "sound.caf", "badge": 2, "alert": "Successfully registered device"}}

我的sound.caf文件位于我的Xcode项目的顶层,它肯定出现在结果中。 app(由Finder中的查看包内容确认)。

My sound.caf file is at the top level of my Xcode project, and it definitely appears in the resulting .app (as confirmed by 'view package contents' in Finder).

声音文件在我的Mac上播放正常。最初我尝试过.caf,.m4r和.wav文件,但没有人会玩。我还试过使用 Urban Airship 示例项目中的一个.caf文件(我我非常自信必须工作,但不可否认我自己也没有尝试过,但这也不起作用。

The sound file plays fine on my Mac. Initially I tried .caf, .m4r and .wav files, but none would play. I have also tried using one of the .caf files from an Urban Airship sample project (which I'm pretty confident must work, but admittedly I haven't tried it myself), but that didn't work either.

Apple docs 定义接受的编码和文件格式(.wav,.aiff或.caf)。

The Apple docs define the accepted encodings and file formats (.wav, .aiff or .caf).

我尝试过很短的声音文件以及较长的声音文件(到请确保我在无证件的30秒限制之下。)

I've tried very short sound files as well as longer ones (to be sure I am underneath the undocumented 30 second limit).

有没有人有任何其他提示/建议供我试用?

Has anybody got any other hints/suggestions for me to try?

推荐答案

我的问题是我实际上并没有在我的测试iPhone上更新应用程序。我正在iTunes中更新版本,但我没有增加Bundle版本,因此iTunes没有将新应用程序推送到手机。

My problem was that I wasn't actually updating the application on my test iPhone. I was updating the version in iTunes, but I hadn't incremented the "Bundle version", so iTunes wasn't pushing the new application to the phone.

要成为确保将更新的应用程序复制到手机中,仔细观看iTunes状态消息。应该说:

To be sure your updated application is being copied to the phone, watch the iTunes status message carefully. It should say:


更新设备上的应用程序

安装应用程序

Updating applications on 'device'
Installing 'application'

如果有疑问,只需从设备中删除现有的应用程序。

If in doubt just delete the existing app from the device.

这篇关于如何使用Apple推送通知获得自定义声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆