未传送APNS中的自定义有效载荷

时间:2018-08-16 08:15:46

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

我们正在使用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)")
}

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

1 个答案:

答案 0 :(得分:0)

也许是因为您使用的是不推荐使用的委托方法。您可以尝试使用新的委托方法。

public class Wrapper : INotifyPropertyChanged
{
    private readonly SharedModel _model;
    public Wrapper(SharedModel model)
    {
        _model = model;
    }

    private string _property;
    public string MyProperty
    {
        get { return _property; }
        set { _property = value; OnPropertyChanged(); }
    }

    //...
    public event PropertyChangedEventHandler PropertyChanged;
}