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.
接下來是具體的實現(xiàn)步驟
1. 服務(wù)器設(shè)置
key = sound 器腋, value = "kakao.caf"
2. xcode工程處理
把制作好的鈴聲添加到項目中虑省,如下圖
注意事項:
- 鈴聲不能超過30s,否則系統(tǒng)會啟用默認(rèn)鈴聲(default)
- 鈴聲只支持
aiff
,wav
, orcaf
- 鈴聲必須打包進(jìn)app中
其實iOS10之后纸颜,系統(tǒng)提供了api,可以在app內(nèi)部更改sound稿壁,也更方便了廣大開發(fā)者佑女。