SNSPublishRequest how to send the aps array and not see the “default” message for APNS

Deadly 提交于 2020-01-05 12:09:17

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/22366310/snspublishrequest-how-to-send-the-aps-array-and-not-see-the-default-message-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!