SNSPublishRequest如何发送APS阵列,而不是看"默认"消息APNS阵列、而不是、消息、SNSPublishRequest

2023-09-11 11:52:12 作者:甘愿全天候

我想用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> \\\}} \};
 

什么是ERP APS和MES

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>\\\"}}\"}";

 
精彩推荐
图片推荐