Frage

I know you can do it with local notifications using the soundName property but that doesn't affect remote notifications. I understand that the normal way to do this is to include the sound reference in the payload, but I do not want to do that every time since I only plan to use one custom sound. There has got to be a simple way to do this.

War es hilfreich?

Lösung

Yes you can override default sound of remote notification. For that you need to change sound property in payload of aps dictionary. You need to set your desired sound file name and include that sound file in your project bundle.

More information regarding payload of aps, please check below image. aps payload

In Apple push notification programming guide, they mentioned as below.

Each push notification includes a payload. The payload contains information about how the system should alert the user as well as any custom data you provide. The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit.

For each notification, compose a JSON dictionary object (as defined by RFC 4627). This dictionary must contain another dictionary identified by the key aps. The aps dictionary contains one or more properties that specify the following actions:

1. An alert message to display to the user
2. A number to badge the application icon with
3. A sound to play

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top