0
votes

I am able to receive push notifications in my app when sending from the Firebase Messaging console.

However, I want an mp3 that is in my app's bundle to play instead of the default sound.

Here's how I send the message: enter image description here

But when I inspect the notification, the value of userInfo["aps"]["sound"] is 'default'. And so it plays the default sound.

The value of userInfo["sound"] is set to my filename, which isn't of help because this is outside of userInfo["aps"].

How do I get the value of userInfo["aps"]["sound"] to be my custom file name? Instead of default.

1

1 Answers

0
votes

It turns out that you can't set a custom value for userInfo["aps"]["sound"] via the Firebase console. So for testing, you'll have to send the push differently.

Instead, you can use the Easy APNs Provider mac app. You supply this with an APS Push Cert that you've previously generated, as well as your device's token (as puctured):

enter image description here

You can obtain the token after approving push services from the app:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    let deviceTokenString = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
    print(deviceTokenString)
}

Now, my custom sound plays because the push's payload is properly structured. It would be nice if Firebase was able to resolve this from their console; in the meantime, I will use this method.