gpt4 book ai didi

ios - 更改推送通知声音

转载 作者:IT王子 更新时间:2023-10-29 08:02:33 27 4
gpt4 key购买 nike

如何为推送通知使用自定义声音?

根据我的研究和阅读,我发现有效负载的文件名应该位于应用程序包中或应用程序数据容器的 Library/Sounds 文件夹中。

如何把文件放在那里?

最佳答案

关注Apple documentation为您的应用准备自定义声音文件。

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 Library/Sounds folder 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 caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the app bundle or to the Library/Sounds folder of your data container.

You can 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.

创建文件后,最简单的方法是将其放入应用程序包中。

然后,当您发送推送通知时,只需在 JSON 负载中添加文件名。示例:

{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
}
}

就是这样!您无需在应用程序代码中执行任何特殊操作。

编辑:
请将文件放入您的项目包中(即在项目层次结构中)并在拖放时选择 Copy items if needed 选项。涂黑部分为项目名称。

enter code here

关于ios - 更改推送通知声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37536591/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com