用户获取推送通知时如何播放自定义声音文件?

用户获取推送通知时如何播放自定义声音文件?

问题描述:

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

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.