gpt4 book ai didi

ios - 亚马逊 AWS SNS : How do i subscribe to SNS topic from iOS?

转载 作者:行者123 更新时间:2023-11-29 12:18:46 45 4
gpt4 key购买 nike

首先我发现了同样的问题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/is it ok 之后资源为什么就断了?除此之外我不明白我应该把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 参数的结果。

关于ios - 亚马逊 AWS SNS : How do i subscribe to SNS topic from iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31300136/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com