如何通过Parse推送通知发送JSON数据

时间:2015-06-15 09:08:04

标签: ios objective-c json xcode parse-platform

我想将JSON数据发送到Parse Push通知我想发送这样的数据:

{ 
  "action": "android.intent.action.PUSH_STATE", 
  "alert": "welcome", 
   "message": "123123,123,123" 
}

我正在使用以下代码:

 NSDictionary * postDictionary = [NSDictionary dictionaryWithObjects:  [NSArray arrayWithObjects:@"action", @"alert",@"message" nil]
                                                                forKeys:[NSArray arrayWithObjects:@"android.intent.action.PUSH_STATE", @"welcome",@"123123,123,123", nil]];

    NSError * error = nil;
    NSData * jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:NSJSONReadingMutableContainers error:&error];

    [push setMessage:jsonData];
    [push sendPushInBackground];

我收到的错误是:

无法初始化NSString类型的参数*使用NSData * ___ Strong

类型的LValue

1 个答案:

答案 0 :(得分:0)

JSON有效负载记录在REST API Push Notifications guide中。 “alert”键应该是“data”哈希中的字符串,而不是“aps”。另外,如果您还没有这样做,请确保在“oid”键中传递一个字符串。

有效的JSON有效负载是:

{
    "data": {
        "alert": "push_notification_msg",
        "sound": "",
        "cdata": {
            "type": 2,
            "oid": "XXX"
        },
        "action-loc-key": "push_notification_btn",
        "loc-key": "push_notification_msg"
    }
}
相关问题