【发布时间】:2015-06-15 09:08:04
【问题描述】:
我想发送 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];
我收到以下错误:
无法使用 NSData* ___Strong 类型的 LValue 初始化 NSString* 类型的参数
【问题讨论】:
-
我认为您必须先将 NSData 对象转换为 NSString 才能使用它。试试“[NSString stringWithUTF8String:[jsonData bytes]]”
-
当我使用这个传递给解析的文本字符串时......我希望发送 json
-
那么我认为你应该使用“setData”而不是“setMessage”。查看文档:parse.com/docs/ios/api/Classes/PFPush.html#//api/name/setData:
-
看起来您在第一个
arrayWithObjects:调用中、@"message"之后和nil之前缺少一个逗号
标签: ios objective-c json xcode parse-platform