如何从客户端设备自定义远程通知标题和 body?

How to customize remote notification title and body from client device?

我想在显示给用户 interface.Especially 之前在我的客户端设备上自定义远程通知,我想编辑标题和 body 以在每次通知到达时显示在 LockScreen、横幅和 NotificationCenter它们显示为 banner.I 不想设置服务器通知标题并且 body.I 只想在显示之前在客户端设备上设置自定义。

有什么办法吗?

有指南吗?

{
    "aps" : {
        "alert" : "",
        "content-available" : 1
    },
    "action" : "update",
    "extraData" : {
        "updateType" : 2,
        "updateMessage" : "New version available 1.1.2"
    }
}

aps 字典必须有键 content-available 和值 1,因此每当您的设备收到带有此键和值的 remote-notification 时,它将被视为 silent-notification。

alert 的值必须是空字符串 ""。否则 iOS 系统将显示该通知。

每当 iOS 操作系统收到 silent-notification 时,它会触发 AppDelegate class 的 application:didReceiveRemoteNotification:fetchCompletionHandler: 方法。在此方法中,您可以通过 userInfo 参数获取通知的有效负载。

在上面的有效载荷中,actionextraData 是我的自定义数据。基于此,您可以处理收到的通知。在上面,我通过附加另一个字符串来更改基于字符串 updateMessage 的通知文本。更改字符串后,您可以安排一个 local-notification:这样您就可以更改收到的文本 remote-notification.

您必须为 remote notifications 启用 background mode