简体   繁体   中英

How to send JSON data via Parse Push Notification

I want to send JSON data to Parse Push notification I want to send data like this:

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

I am using following code:

 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];

I am getting error that:

Cannot initialize the paramaeter of type NSString* With an LValue of type NSData* ___Strong

The JSON payload is documented in the REST API Push Notifications guide . The "alert" key should be a string within the "data" hash, not "aps". Also, make sure to pass a string in your "oid" key, if you're not doing so already.

A valid JSON payload would be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM