Custom iOS push notification sound

2019-03-09 14:14发布

问题:

I have been facing an issue. I implemented push notification in iOS with custom sound. Its a MP3 file. It plays well when I receive a push notification in iOS 5, but in iOS4, it doesn't play any sound. Can you help me with this?

The code is like this

{
    "aps": {
        "badge": 10,
        "alert": "Hello",
        "sound": "sound.mp3"
    }
}

Nithin

回答1:

According to the push notification guide:

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 application bundle.

It doesn't say anything about MP3s. I've used aif files which worked. I'd stick to what Apple specifies.



回答2:

You can't play .mp3-files. However, you can convert them into .wav files here: http://media.io/ (online & free). Then put the converted file in your XCode project and you can call it by specifying "sound":"sound.wav"