iOS开发之极光推送自定义推送声音
2016-06-01 10:17
483 查看
项目中用到了自定义推送声音,于是就看了下官方文档。 官方文档上说:
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 can be in the main bundle of
the client app or in the
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 or to the
You can 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.
以上实际上就是说了
由于自定义通知声音还是由 iOS 系统来播放的,所以对音频数据格式有限制,可以是如下四种之一:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
对应音频文件格式是
可以使用
自定义通知声音的播放时间必须在 30s 内,如果超过这个限制,则将用系统默认通知声音替代。
转换完成后就可以将
test.caf这个文件拖入
Xcode 工程中,编译运行项目在真机上。
然后在极光发送推送通知时,只需配置
![](http://img.blog.csdn.net/20160601101608989?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
测试,收到推送时,通知声音就是我们自定义的声音了。
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 can be in the main bundle ofthe client app or in the
Library/Soundsfolder of the app’s data container.
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 or to the
Library/Soundsfolder of your data container.
You can 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.
以上实际上就是说了
由于自定义通知声音还是由 iOS 系统来播放的,所以对音频数据格式有限制,可以是如下四种之一:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
对应音频文件格式是
aiff,
wav,
caf文件,文件也必须放到 app 的
mainBundle目录中。
可以使用
afconvert工具来处理音频文件格式,在终端中敲入如下命令就可以将一个
mp3文件转换成
caf文件:
afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/test.caf -d ima4 -f caff -v |
转换完成后就可以将
test.caf这个文件拖入
Xcode 工程中,编译运行项目在真机上。
然后在极光发送推送通知时,只需配置
sound字段的值为导入到工程中的音频文件名,这里即就是
test.caf。如图所示。
测试,收到推送时,通知声音就是我们自定义的声音了。
相关文章推荐
- 极光推送5大新产品闪耀亮相
- 极光推送java.lang.UnsatisfiedLinkError:错误的解决
- Android极光推送入门
- 项目实战:iOS极光推送集成(30分钟搞定)
- Android Studio打包第三方库自带的so文件的其中一种方法
- 埋在我和极光推送之间的那些坑,好用的极光推送文档
- iOS极光推送证书
- iOS第三方集成之jpush极光推送
- 极光推送
- 极光推送服务端向手机app即时推送消息或通知
- iOS极光推送集成
- 极光推送接入-客户端
- ios后台推送那点事
- Android JPush(极光推送)的使用教程
- iOS 集成极光推送(一)
- iOS 集成极光推送(二)
- iOS开发之极光推送相关问题(library not found for -lPushSDK)
- 极光推送 cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY 错误解决方法
- 给自己的项目做极光推送的步骤
- 通过看极光网站的文档,给自己的项目做极光推送的步骤