I have several pieces of metadata that I need to associate with a push notification.
For example user no, message id.
Can I send more parameters than what apple supports:
{aps = {
alert = joetheman;
sound = default;
};}
Is this possible?
Yes. In the Push Notification Programming Guide section The Notification Payload it states
Providers can specify custom payload values outside the Apple-reserved aps namespace. Custom values must use the JSON structured and primitive types: dictionary (object), array, string, number, and Boolean. You should not include customer information as custom payload data. Instead, use it for such purposes as setting context (for the user interface) or internal metrics. For example, a custom payload value might be a conversation identifier for use by an instant-message client application or a timestamp identifying when the provider sent the notification. Any action associated with an alert message should not be destructive—for example, deleting data on the device.
So your payload might look like
{
"aps": {
"alert": "joetheman",
"sound": "default"
},
"message": "Some custom message for your app",
"id": 1234
}
Further down on that same page are a number of examples that demonstrate this.
Of course. You can send custom parameters as payload with apple push notification. Like Kevin Ballard said the payload will looks like the above. But remember one thing always you are dealing with push notification, As per the apple constraints the push notifications, The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this. So please take this too in your consideration when you are going to add more data to notification.
You are not allowed to put custom tags inside aps tag. Here's what documentations says about it:
Providers can specify custom payload values outside the Apple-reserved aps namespace. Custom values must use the JSON structured and primitive types: dictionary (object), array, string, number, and Boolean.
So in your case you should do something like:
{
"aps": {
"alert": "Hello Push",
"sound": "default"
},
"People": {
"Address": "Your address here",
"Name": "Your Name here",
"Number": "XXXXXXXXXX"
}
}
Therefore you can read your custom payload with looking for it's key in main JSON, rather than in "aps":