用户获取推送通知时如何播放自定义声音文件? [英] How to play custom sound file when user get push notification?

查看:79
本文介绍了用户获取推送通知时如何播放自定义声音文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序包中有一个声音文件,我希望在用户获得推送通知时播放该声音文件。

I have a sound file in the app bundle, i want to play that sound file when user will get push notification.

如果是,是否可以在iOS中播放那么请建议实现这一目标的方法。

IS it possible in iOS if yes, then please suggest the way to achieve this.

谢谢,

推荐答案

要播放此声音,您必须在通知有效负载中指定声音的文件名。例如,假设您已将一个名为example.caf的声音文件添加到您的应用程序中,我们可以使用通知有效负载播放此声音,如下所示:

To play this sound you must specify the filename of the sound in the notification payload. For example, lets say you've added a sound file named example.caf into your application, we can play this sound with the notification payload as below:

{
    aps =     
    {
        alert = "test example notification message";
        sound = "example.caf";
    };
}

然后,当您的通知到达时,自定义声音将会播放。

Then the custom sound will play when your notification arrives.

这篇关于用户获取推送通知时如何播放自定义声音文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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