简体   繁体   English

iOS推送通知-如何指定通知声音

[英]IOS Push Notification - how to specify sound for notification

I'm trying set a sound for my notification but its not working in the device please tell me how to set the alert sound for the notification. 我正在尝试为通知设置声音,但该声音在设备中不起作用,请告诉我如何为通知设置警报声音。

$payload = '{
    "aps" :
    {
        "alert" :"'.$message.'",
        "badge" : 1,
        "sound" : "default"
    }  
}';

i have used the above code the set a sound for the push notification its not working pls tell where I'm wrong. 我已经使用了上面的代码为推送通知设置了一个声音,但它不起作用,请告诉我我错了。

The code you have written is fine, one thing you can do is do not send the sound key val pair if you want to play the default send, as per apple docs if there is no data for sound it will play the default sound. 您编写的代码很好,您可以做的一件事是,如果您要播放默认的send,则不要发送音键val对, 按照apple docs的规定,如果没有声音数据,它将播放默认的声音。

possible duplicate 可能重复

You can either remove this key/pair value if you want to play one of the default sounds or you can use one of the default sounds available. 如果要播放默认声音之一,则可以删除此键/对值,也可以使用可用的默认声音之一。 You can also play one of your own sounds by including the sound file in your app's bundle (check the documentation on which sound files and how to convert them) and then referencing the name of the sound file in the payload. 您还可以通过将声音文件包含在应用程序的捆绑软件中来播放自己的声音之一(检查有关哪些声音文件以及如何转换它们的文档 ),然后在有效负载中引用声音文件的名称。

For example, if you have a custom sound file "cat.caf", you would reference it in the payload. 例如,如果您有一个自定义的声音文件“ cat.caf”,则可以在有效负载中对​​其进行引用。

Tip: To save some bytes on your push notification payload, make the sound files as short as possible, even down to a single letter. 提示:要在推送通知有效负载上节省一些字节,请使声音文件尽可能短,甚至减小到单个字母。 Renaming "cat.caf" to c works just fine. 将“ cat.caf”重命名为c可以正常工作。 Example: 例:

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

This is the available Official documentation. 这是可用的官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM