Is aps dictionary necessary in iOS notification payload? Can we have same payload for iOS and Android?

ⅰ亾dé卋堺 提交于 2019-12-06 07:28:39

Update for cross-platform payloads: A recent feature was added for FCM that gives an option to provide specific params for specific platforms, called Platform Overrides.


The sample payload you posted seems to be in-line with the official parameters for APNs. When using GCM or FCM, the parameters to be used are different (see the links).

Is there a standard format defined in Android for notifications or can you set any data in Android and the client has to manually handle and display these notifications?

It depends on which type of message payload you're planning to use. There are 2 types of Messages for GCM/FCM, notification and data.

notification messages only have predefined set of parameters available, while data messages can be used to have custom key-value pairs. Both are usually handled by the client, but note that the behavior for Android and iOS are different depending on the message type you use (see the links).

How can I create a payload which works for both?

As I mentioned in comments section in the other post:

You'll have to do the mapping in your own database/app server. Yes. What I was thinking here was every time a registration token is generated on the client app side, you send it to your database/app server along the type of device (i.e. "Android", "iOS"). So that when you'll be sending messages, you'll first have to check the type of device. I did say it's more work, but it's a sure way to give you control over things. AFAIK, it is the developer's responsibility to keep track of the registration tokens and any details that should be associated with it.

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 World",
        "sound": "default"
    },
    "Person": {
        "Address": "Your address",
        "Name": "Your Name",
        "Number": "XXXXXXXXXX"
    }
}

Therefore you can read your custom payload with looking for it's key in main JSON, rather than in "aps":

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!