【问题标题】:Custom payload in APNS not deliveredAPNS 中的自定义有效负载未交付
【发布时间】:2019-01-23 03:31:36
【问题描述】:

我们正在使用 APNS 向外部设备发送推送通知。有效载荷如下所示:

{
    "data":{
        "aps":{
            "alert":{
                "loc-args":["bharathp"],
                "loc-key":"LiKudoAlertBody",
                "title-loc-key":"LiKudoAlertTitle"
            }
        },
        "fromName":"bharathp",
        "source":"community",
        "type":"kudos",
        "message":"{....some dictionary....}",
        "fromId":"1696757163"
    },
"to":"some string"
}

但在 iOS 上,当我收到通知时,我只会收到有效负载的“aps”部分。

[AnyHashable("aps"): {
alert =     {
    "loc-args" =         (
        bharathp
    );
    "loc-key" = LiKudoAlertBody;
    "title-loc-key" = LiKudoAlertTitle;
};
}]

我正在使用

打印上述内容
func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {
        // Print notification payload data
        print("Push notification received: \(data)")
}

我发送的格式不正确吗?这可能是什么问题?

【问题讨论】:

  • 这不是 APNS 负载的标准格式,您是否使用 3rd 方服务来发送通知?
  • 这不是标准格式。试试这样,{ "aps" : { "alert" : { "title" : "Manish Kumar", "body" : "iOS Developer" }, }, "data" : { //你的数据在这里 } }

标签: ios swift push-notification apple-push-notifications


【解决方案1】:

可能是因为您使用了已弃用的委托方法。您可以尝试使用新的委托方法。

@available(iOS, introduced: 3.0, deprecated: 10.0, message: "Use UserNotifications Framework's -[UNUserNotificationCenterDelegate willPresentNotification:withCompletionHandler:] or -[UNUserNotificationCenterDelegate didReceiveNotificationResponse:withCompletionHandler:] for user visible notifications and -[UIApplicationDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] for silent remote notifications")
optional public func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-28
    • 1970-01-01
    • 2017-08-23
    • 2013-10-19
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    相关资源
    最近更新 更多