question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set custom fields in aps alert dictionary

See original GitHub issue

Hello, thanks for creating Pushy. I have a VOIP app which requires data payload with its alert dictionary in this format:

"alert": { "uuid": "xxxx", "incoming_caller_id": "yyy", "incoming_caller_name": "zzz", }

How can I add these custom keys (uuid, incoming_caller_id, incoming_caller_name) to the alert dictionary? I have gone through the docs for ApnsPayloadBuilder, and I could see methods to set standard fields (e.g. setAlertBody) and I could see a method called setLocalizedAlertMessage.

I thought of using setLocalizedAlertMessage("uuid", "xxxx") - however looking into its implementation, it seemed that it will create two separate entries in the alert dictionary (e.g. {"loc-key" : "uuid", "loc-args" : ["xxxx"]}), so I’m unsure it will work. Kindly help.

P.S. The format of the alert dictionary is mandated by a Flutter package (Flutter VOIP IOS Kit) that I’m using at my Frontend.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jchamberscommented, Apr 5, 2021

The payload of an ApnsPushNotification is just a String. You can pass any value—legal or not—as the payload.

1reaction
jchamberscommented, Apr 4, 2021

The closest thing we have is ApnsPayloadBuilder#addCustomProperty(String, Object), but it sounds like that’s not what you need.

It sounds like what Flutter is asking you to do goes against what Apple’s docs specify. The docs say (emphasis added):

In addition to the Apple-defined keys, you may add custom keys to your payload to deliver small amounts of data to your app, notification service app extension, or notification content app extension. Your custom keys must have values with primitive types, such as dictionary, array, string, number, or Boolean. Custom keys are available in the userInfo dictionary of the UNNotificationContent object delivered to your app.

Typically, you use custom keys to help your code process the notification. For example, you might include an identifier string that your code can use to look up app-specific data. Add app-specific keys as peers of the aps dictionary.

…so adding new keys to the alert dictionary inside of aps would violate that guidance, and I don’t think that’s something we want to add to Pushy.

That said, remember that payloads are just JSON objects, and you can construct them however you’d like! You could use the JSON library of your choice to encode arbitrary objects, or even just use String#format if you want.

Because there’s a viable workaround, because this doesn’t appear to be a widespread need, and because it would go against the official docs, I’m going to close this as “won’t fix.”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generating a remote notification - Apple Developer
Specify the payload for a remote notification using a JSON dictionary. ... Don't add your own custom keys to the aps dictionary; APNs...
Read more >
3 Remote Notification Payload Written by Scott Grosch - Kodeco
A push notification is constructed and delivered based on a payload structure. In this chapter you'll dive deep into all of the possibly...
Read more >
Are content-available and alert mutually exclusive keys in an ...
These messages have a set of custom keys outside the aps dictionary that we use to provide different treatments, etc. However, if the...
Read more >
Create and work with custom fields - Dynamics 365
This article shows you how to create custom fields through the user interface to tailor the application to fit your business.
Read more >
Aps.Builder | Firebase - Google
build(). Builds a new Aps instance from the fields set on this builder. ... Puts a custom key-value pair to the aps dictionary....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found