更改推送通知声音 [英] Change push notification sound

查看:18
本文介绍了更改推送通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

如何把文件放在那里?

解决方案

Follow

How can I use a custom sound for push notifications?

According to my research and reading, I have found that the payload should have file name that is in the app bundle or in the Library/Sounds folder of the app’s data container.

How to put file there?

解决方案

Follow Apple documentation for preparing custom sound file for your app.

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.

Once you have made the file, easiest way is to put it in app bundle.

The, when you send push notification, just add the name of file in JSON payload. Example:

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

Thats it! You don't have to do anything special in code of app.

Edit:
Please put the file inside your project bundle (i.e inside the hierarchy of project) and have Copy items if needed option selected while drag and drop. The blacked out part has project name.

这篇关于更改推送通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆