1
votes

Using Backendless for Push Notifications, and my devices successfully receive them. But when I try to set the "ios-sound" parameter of the message to an mp3 I added to my project, it does not play any sound:

enter image description here

Here in the Backendless docs it says that setting "ios-sound" does the following:

Sets either a URL for the sound notification to play on the device or an array of bytes for the sound to play.

I can't figure out what I'm doing wrong. Hmm...

2
I am able to play the sound when a user is currently in the app / has the app opened through by referencing the "ios-sound" value from the userInfo dictionary in the AppDelegate's didReceiveRemoteNotification: method. However, the sound does not play when the app is close or in the background.vikzilla
its not ios-sound, just sound, and mp3 file is not Apple's sound file extension, they only support caf, aiff,... convert your files to that with itunes then u can use itTj3n
@Tj3n it is indeed "ios-sound". I confirmed this by logging out the userInfo from didReceiveRemoteNotification. However the only issue now is playing a sound / reacting to a push notify when the app is not open / in background. Also, I do not know what you mean by mp3 not being supported; it plays just fine and I have used it many times in the past.vikzilla
Hmm... in the payload guide by Apple it said that music name should be in sound param and in caf or aiff extension, maybe try to convert first to see?Tj3n
I get the path of my mp3 from the userInfo, and then play the sound via AudioServices.vikzilla

2 Answers

2
votes

if you are recieving notification successfully on ur device , then there might be chances that your audio file is large

Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.,so make sure that your custom sound is less than 30 sec.

Your audio data must be in an aiff, wav, or caf file.

the file name on server and your file in bundle should be of same name . and just convert your mp3 into one of the given format then only sound bud play when app is in inactive state.

2
votes

The problem was resolved by calling registerUserNotificationSettings in addition to registerForRemoteNotifications() which I was already doing.

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)

    //NEEDED TO DO THE FOLLOWING TWO LINES
    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
    UIApplication.sharedApplication().registerUserNotificationSettings(settings)

    UIApplication.sharedApplication().registerForRemoteNotifications()

    return true
  }

The reason I was not calling this before was because the Backendless Docs said that simply calling .registerForRemoteNotifications() covers alerts, badges, and sounds. However this seems to be incorrect.