简体   繁体   中英

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.

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.

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. Example:

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

This is the available Official documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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