apns可以自定义sound,支持三种格式 aiff
,wav
, or caf
file
官方文档中有铃声格式和长度的说明:
Preparing Custom Alert Sounds
截取原文贴出来:
Preparing Custom Alert Sounds
Local and remote notifications can specify custom alert sounds to be played when the notification is delivered. You can package the audio data in an aiff,wav, or caf file. Because they are played by the system-sound facility, custom sounds must be in one of the following audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
Place custom sound files in your app bundle or in theLibrary/Soundsfolder of your app’s container directory. Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.
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
For information on how to associate a sound file with a notification, see Adding a Sound to the Notification Content.
接下来是具体的实现步骤
1. 服务器设置
key = sound , value = "kakao.caf"
2. xcode工程处理
把制作好的铃声添加到项目中,如下图
cmd-markdown-logo
注意事项:
- 铃声不能超过30s,否则系统会启用默认铃声(default)
- 铃声只支持
aiff
,wav
, orcaf
- 铃声必须打包进app中
其实iOS10之后,系统提供了api,可以在app内部更改sound,也更方便了广大开发者。
网友评论