问题
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