Hello, I'm doing some test and I dowload the sample from here https://developer.apple.com/documentation/networkextension/local_push_connectivity/receiving_voice_and_text_communications_on_a_local_network
Everything works correctly and the phones are able to exchange messages without problems and the server sends pushes to the devices.
Now I would like to modify the server so that, when it sends the push to the mobile device, it can change the sound or add other information as is possible when using APN.
Now I would like to modify the server so that, when it sends the push to the mobile device, it can change the sound or add other information as is possible when using APN. Is there any way to send a payload like for APN?
Thank's Omar
Yes. The "message" you send from your server is basically freeform. You can serialize any data you want to a JSON, or any other format appropriate to your use case and send it to the client.
Then on the receiving side, you can deserialize and interpret the incoming message in any way you wish. If you send an equivalent of an APNs payload, then you can convert that data into the various properties of a UNMutableNotificationContent()
variable. In the given example project, you could do this interpretation in the function showLocalNotification(message: TextMessage)
(or anywhere else you find appropriate for your case)
For the specific example of a custom sound, in the payload within message
you can interpret a "sound" entry, and then either pick a sound already bundled with your app, or send a URL for the client to download a sound file into Library/Sounds
directory and use that as the content.sound
entry.
You can read more about notification sounds at UNNotificationSound
While you are free to choose any format you like to pass on your custom data, if you use the existing aps
payload format as described in Generating a remote notification, it will be a well defined and commonly used format, and if in the future you want to use both local push and APNs push with the same infrastructure, you will already be creating the correct payload for both.
Argun Tekant / DTS Engineer / Core Technologies