user5068763 user5068763 - 6 months ago 189
iOS Question

IOS change push notification sound

How to I can change push notification sound?

I had research and found this way.

The name of a sound file in the app bundle or in the Library/Sounds folder of the app’s data container

So, how to I can do this.

Please help me.

Answer

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.

enter code here

Comments