SNSPublishRequest如何发送APS阵列,而不是看"默认"消息APNS [英] SNSPublishRequest how to send the aps array and not see the "default" message for APNS
问题描述
我想用SNSPublishRequest发布到SNS,但我无法弄清楚如何格式化JSON实际使用的APS字典中设置的参数。如果我把东西给了默认,它将发送该消息。但是,如果我添加了APNS字典为好,它似乎没有显示任何东西。这是我如何格式化JSON请求 - ?我失去了一些东西。
的NSDictionary *参数= @ {@默认:@,
@APNS:@ {@APS:@ {@警告:@你好}}};
NSError *错误;
的NSData * jsonData = [NSJSONSerialization dataWithJSONObject:参数
选项:0
错误:放大器;错误]
的NSString * JSONString = [[NSString的页头] initWithBytes:[jsonData字节]长:[jsonData长]编码:NSUTF8StringEncoding]。
的NSLog(@JSON输出:%@,JSONString);
SNSPublishRequest * PR = [[SNSPublishRequest页头] initWithTopicArn:@someTopicandMessage:JSONString]。
pr.messageStructure = @JSON;
我觉得SNS的的APN字典期待一个JSON EN codeD字符串格式本身。我们要逃离一切,并添加\ S
的NSString * JSONString = @{\默认\:\<在这里输入你的信息和GT; \,\APNS_SANDBOX \:\{\\\ APS \\\:{\\\警报\\\:\\\< HELLO> \\\}} \};
I am trying to publish to SNS using the SNSPublishRequest but I can't figure out how to format the JSON to actually use the parameters set for the aps dictionary. If I put in something for the "default" it will send that message. But if I add the APNS dictionary as well, it seems to not show anything. This is how I am formatting the JSON request - am I missing something?
NSDictionary *parameters = @{@"default" : @"",
@"APNS" : @{@"aps": @{@"alert": @"hello"}}};
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters
options:0
error:&error];
NSString *JSONString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];
NSLog(@"JSON OUTPUT: %@",JSONString);
SNSPublishRequest *pr = [[SNSPublishRequest alloc] initWithTopicArn:@"someTopic" andMessage:JSONString];
pr.messageStructure = @"json";
I think SNS's APNs dictionary expects an JSON encoded string format itself. We have to escape all the " and add the \s
NSString* JSONString = @"{\"default\": \"<enter your message here>\",\"APNS_SANDBOX\":\"{\\\"aps\\\":{\\\"alert\\\":\\\"<HELLO>\\\"}}\"}";
这篇关于SNSPublishRequest如何发送APS阵列,而不是看&QUOT;默认&QUOT;消息APNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!