【发布时间】:2015-09-26 19:18:21
【问题描述】:
首先我发现了同样的问题here,但它不起作用......也许AWS SDK发生了变化或其他什么,我不知道为什么......我想从我的订阅SNS主题iOS 应用程序。我正在尝试使用该答案中的代码来做到这一点,我试图对其进行更改以消除错误:
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 放在哪里? 我真的需要帮助!先谢谢了?
我的 Cognito 角色是:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sns:CreatePlatformEndpoint",
"sns:Subscribe",
"sns:CreatePlatformApplication",
"sns:*"
],
"Resource": [
"arn:aws:sns:*"
]
}
]
}
我正在使用最新的 AWS 开发工具包:
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)
【问题讨论】:
-
Message=User: arn:aws:sts::753780999999:assumed-role/Cognito_MyAppUnauth_Role/CognitoIdentityCredentials 无权执行:SNS:CreatePlatformApplication
-
没有。我试图添加该角色。错误是一样的。我完全不明白为什么要削减资源...为什么“无权执行:SNS:CreatePlatformApplication on resource:arn:aws:sns:us-east-1:753780999999:app/”而不是“arn: aws:sns:us-east-1:753780999999:app/APNS_SANDBOX/MyAppDevelopment"...反正我也不知道怎么回事...
-
你确定你修改了正确的角色吗?您是否尝试过将资源更改为“*”以查看是否可以解除阻止?
-
@BobKinney 好的,我将 cognito 的角色修改为 *。现在我有错误:
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...等等... -
@BobKinney 我将
continueWithBlock:^id(AWSTask *task)更改为 AWSTask 并且错误消失了。但我不明白`不兼容的指针类型将 AWSSNSCreatePlatformEndpointInput * 发送到 AWSSNSCreatePlatformApplicationInput * 类型的参数...你说的是最新的 SDK,但我已经在使用 AWS SDK 2.2。
标签: ios objective-c amazon-web-services amazon-sns amazon-cognito