android - iOS 通知负载中是否需要 aps 字典?我们可以为 iOS 和 Android 使用相同的有效负载吗?

标签 android ios google-cloud-messaging apple-push-notifications firebase-cloud-messaging

我刚开始研究 iOS 上的通知,苹果似乎已经定义了一种有效载荷接收通知的格式。

所以目前,我正在使用这个有效载荷,一切都按预期工作。我正在获取标题、副标题、主体声音、图像。

{"aps" : {
        "alert" : {
            "title" : "Introduction To Notification",
            "subtitle" : "Session 707",
            "body" : "New Notification Look Amazing"
        },
       "sound" : "default",
        "category" : "message",
        "badge" : 1,
        "mutable-content": 1
    },
    "attachment-url": "https://pusher.com/static_logos/320x320.png"
}

假设我想为 Android 和 iOS 使用一个有效载荷。

Android 中是否为通知定义了标准格式,或者您是否可以在 Android 中设置任何数据,客户端必须手动处理和显示这些通知?

如何创建适用于两者的负载?

最佳答案

跨平台负载更新:最近为 FCM 添加了一项功能,该功能提供了为特定平台提供特定参数的选项,称为 Platform Overrides .


您发布的示例负载似乎符合 official parameters for APNs .使用 GCM 时或 FCM ,要使用的参数不同(请参阅链接)。

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?

这取决于您计划使用哪种类型的消息负载。有2 types of Messages对于 GCM/FCM,notificationdata

notification消息只有一组可用的预定义参数,而 data消息可用于具有自定义键值对。两者通常都由客户端处理,但请注意 Android 的行为和 iOS取决于您使用的消息类型(请参阅链接)。

How can I create a payload which works for both?

正如我在 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.

关于android - iOS 通知负载中是否需要 aps 字典?我们可以为 iOS 和 Android 使用相同的有效负载吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42218480/

相关文章:

php - Android和PHP登录认证

java - 应用程序在@Override 点不断崩溃

ios - 如何从 UITableViewController 中删除行

google-cloud-messaging - FCM 和 GCM 是否向后和向前兼容?

android - 如何在android studio中导入GcmListenerService?

android - 为流发布设置 facebook 权限

javascript - HTML anchor 标记无法在 Android 平台中下载文件

ios - 奇怪的 UINavigationBar 行为?

ios - iOS:如何更改字符串中某些字符的颜色/字体

android - FCM Token会像GCM注册ID一样周期性变化吗?