CreatePlatformApplication

CreatePlatformApplication

首先,我发现了相同的问题here,但它不起作用...也许是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放在哪里?
我真的需要帮助!提前致谢?

我的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)

最佳答案

抱歉,很遗憾,您复制了包含错字的代码:

createPlatformApplication:endpointRequest

应该:
createPlatformEndpoint:endpointRequest

您的原始策略中不允许使用CreatePlatformApplication方法。一旦允许sns:*,该服务就允许该调用,但是请求不包含CreatePlatformApplication所需的参数,因此包括ValidationError。原始消息中修剪的ARN也是由于缺少CreatePlatformApplication参数的结果。

10-06 11:17