无法自动为端点订阅主题,但您可以通过代码完成所有操作。
Subscribe
创建端点后,您可以直接调用API。与其他类型的订阅不同,SNS 移动推送不需要确认。
下面是一些示例 Objective-C 代码,它创建一个端点并将其订阅到一个主题:
AWSSNS *sns = [AWSSNS defaultSNS];
AWSSNSCreatePlatformEndpointInput *endpointRequest = [AWSSNSCreatePlatformEndpointInput new];
endpointRequest.platformApplicationArn = MY_PLATFORM_ARN;
endpointRequest.token = MY_TOKEN;
[[[sns createPlatformEndpoint:endpointRequest] continueWithSuccessBlock:^id(AWSTask *task) {
AWSSNSCreateEndpointResponse *response = task.result;
AWSSNSSubscribeInput *subscribeRequest = [AWSSNSSubscribeInput new];
subscribeRequest.endpoint = response.endpointArn;
subscribeRequest.protocols = @"application";
subscribeRequest.topicArn = MY_TOPIC_ARN;
return [sns subscribe:subscribeRequest];
}] continueWithBlock:^id(BFTask *task) {
if (task.cancelled) {
NSLog(@"Task cancelled");
}
else if (task.error) {
NSLog(@"Error occurred: [%@]", task.error);
}
else {
NSLog(@"Success");
}
return nil;
}];
确保您已在您的 Cognito 角色中授予访问权限,sns:Subscribe
以允许您的应用程序进行此调用。
2015-07-08 更新:更新以反映 AWS iOS SDK 2.2.0+