我是靠谱客的博主 个性长颈鹿,最近开发中收集的这篇文章主要介绍iOS学习爬坑记录14:自定义远程推送通知铃声(Custom Alert Sounds),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

最近在调试APP的远程推送,需要做成类似微信视频通话或者语音通话的通知铃声。找了好多资料才知道怎么自定义铃声:

官方文档中有铃声格式和长度的说明:(见https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6)

Preparing Custom Alert Sounds

For remote notifications in iOS, you can specify a custom sound that iOS plays when it presents a local or remote notification for an app. The sound files must be in the main bundle of the client app.

Custom alert sounds are played by the iOS system-sound facility, so they must be in one of the following audio data formats:

  • Linear PCM

  • MA4 (IMA/ADPCM)

  • µLaw

  • aLaw

You can package the audio data in an aiffwav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle.

You may use the afconvert tool to convert sounds. For example, to convert the 16-bit linear PCM system sound Submarine.aiff to IMA4 audio in a CAF file, use the following command in the Terminal app:

afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v

You can inspect a sound to determine its data format by opening it in QuickTime Player and choosing Show Movie Inspector from the Movie menu.

Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.


因为我做远程推送实验是参考了其他大牛在本机上写的php文件模拟的服务器,自定义铃声也是在php文件中修改(服务器发给APNS的消息中)所以php文件节选如下:

// Create the payload body

$body['aps'] = array(

                    'alert' => '逗你玩!哈哈。',

                    'sound' => 'Synth222.caf',

                    'badge' => 8

                    );

这里面的sound键值就是我的自定义铃声。

把制作好的铃声添加到项目的main bundle中后,还有关键的一步,就是在项目设置中Build Phases-》Copy Bundle Resources中添加你添加的声音文件(我这里是Synth222.caf),铃声不能超过30s,否则系统会启用默认铃声(default)。


关于php文件的详细内容和远程推送详细过程可以参见:http://blog.csdn.net/shenjie12345678/article/details/41120637,谢谢原作者的分享。











最后

以上就是个性长颈鹿为你收集整理的iOS学习爬坑记录14:自定义远程推送通知铃声(Custom Alert Sounds)的全部内容,希望文章能够帮你解决iOS学习爬坑记录14:自定义远程推送通知铃声(Custom Alert Sounds)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部