亚马逊AWS SNS:我如何订阅从iOS的SNS主题?

首先,我在这里find了同样的问题,但这不起作用…也许AWS SDK更改或其他内容,我不知道为什么…我想从我的iOS应用程序订阅SNS主题。 我正在尝试使用该答案的代码,我试图改变以摆脱错误:

AWSSNS *sns = [AWSSNS defaultSNS]; AWSSNSCreatePlatformEndpointInput *endpointRequest = [AWSSNSCreatePlatformEndpointInput new]; endpointRequest.platformApplicationArn = @"arn:aws:sns:us-east-1:753780999999:app/APNS_SANDBOX/MyAppDevelopment"; endpointRequest.token = [self deviceTokenAsString:deviceToken]; [[[sns createPlatformApplication:endpointRequest] continueWithSuccessBlock:^id(AWSTask *task) { AWSSNSCreateEndpointResponse *response = task.result; AWSSNSSubscribeInput *subscribeRequest = [AWSSNSSubscribeInput new]; subscribeRequest.endpoint = response.endpointArn; subscribeRequest.protocols = @"application"; subscribeRequest.topicArn = @"arn:aws:sns:us-east-1:753780999999:MyAppDevelopingTest"; return [sns subscribe:subscribeRequest]; }] continueWithBlock:^id(AWSTask *task) { if (task.cancelled) { NSLog(@"Task cancelled"); } else if (task.error) { NSLog(@"Error occurred: [%@]", task.error); } else { NSLog(@"Success"); } return nil; }]; 

但是我得到的错误:

 Error occurred: [Error Domain=com.amazonaws.AWSSNSErrorDomain Code=0 "The operation couldn't be completed. (com.amazonaws.AWSSNSErrorDomain error 0.)" UserInfo=0x17ee0950 {Type=Sender, Message=3 validation errors detected: Value null at 'name' failed to satisfy constraint: Member must not be null; Value null at 'attributes' failed to satisfy constraint: Member must not be null; Value null at 'platform' failed to satisfy constraint: Member must not be null, __text=( "\n ", "\n ", "\n ", "\n " ), Code=ValidationError}] 

为什么这样? 为什么资源在app /可用之后被切断? 除此之外,我不明白我应该把deviceToken放在哪里? 我真的需要帮助! 提前致谢?

我的Cognitoangular色是:

 { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "sns:CreatePlatformEndpoint", "sns:Subscribe", "sns:CreatePlatformApplication", "sns:*" ], "Resource": [ "arn:aws:sns:*" ] } ] } 

我正在使用最新的AWS SDK:

 Installing AWSCognito 2.2.1 (was 2.2.0) Installing AWSCore 2.2.1 (was 2.2.0) Installing AWSSNS 2.2.1 (was 2.2.0) 

抱歉,不幸的是,您复制了包含错字的代码:

 createPlatformApplication:endpointRequest 

应该:

 createPlatformEndpoint:endpointRequest 

原始策略中不允许CreatePlatformApplication方法。 一旦你允许sns:*,这个调用被服务所允许,但是这个请求并没有包含CreatePlatformApplication所需的参数,所以就是ValidationError。 原始消息中的修剪后的ARN也是缺lessCreatePlatformApplication参数的结果。