iOS学习爬坑记录14:自定义远程推送通知铃声(Custom Alert Sounds)
2015-03-09 10:26
211 查看
最近在调试APP的远程推送,需要做成类似微信视频通话或者语音通话的通知铃声。找了好多资料才知道怎么自定义铃声:
官方文档中有铃声格式和长度的说明:(见https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6)
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
Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle.
You may use the
IMA4 audio in a CAF file, use the following command in the Terminal app:
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,谢谢原作者的分享。
官方文档中有铃声格式和长度的说明:(见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 ofthe 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
aiff,
wav, or
caffile.
Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle.
You may use the
afconverttool to convert sounds. For example, to convert the 16-bit linear PCM system sound
Submarine.aiffto
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 |
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学习爬坑记录8:关于自定义Cell的一点认识
- iOS学习笔记之远程推送、静默推送与自定义消息推送
- ]IOS开发之----远程推送通知
- IOS开发之----远程推送通知
- iOS学习爬坑记录2:往NSMutableArray添加NSDictionary元素失败
- iOS学习爬坑记录10:在Storyboard中打开preview的方法
- iOS学习爬坑记录6: 为Xcode 6.1添加Empty Application project template
- [转载]IOS开发之----远程推送通知
- IOS_CustomView_学习记录
- iOS学习爬坑记录3:plist文件的读写,以及向NSMutableArray中写入NSDictionary元素失败
- iOS本地通知和远程推送
- iOS学习爬坑记录9:Xcode6.1 添加Framework
- 转:IOS远程推送通知
- IOS开发之----远程推送通知
- iOS 远程推送通知 java
- ios学习--ios本地通知和远程通知
- iOS远程推送通知
- iOS—如何在客户端和服务端配置APNs远程推送通知的方法
- iOS学习爬坑记录7:获取设备拥有的font family和font