亚马逊AWS SNS:我如何订阅SNS主题从iOS的? [英] Amazon AWS SNS: How do i subscribe to SNS topic from iOS?
问题描述
首先,我发现了同样的问题<一href="http://stackoverflow.com/questions/26974852/amazon-aws-how-do-i-subscribe-an-endpoint-to-sns-topic">here,但它不工作...也许AWS SDK的变化还是别的什么,我也不知道为什么......我想订阅SNS的话题从我的iOS应用。我想从这个问题的答案,code做到这一点,我试图改变摆脱错误的:
AWSSNS * SNS = [AWSSNS defaultSNS]
AWSSNSCreatePlatformEndpointInput * endpointRequest = [AWSSNSCreatePlatformEndpointInput新]
endpointRequest.platformApplicationArn = @ARN:AWS:SNS:美国东部-1:753780999999:应用程序/ APNS_SANDBOX / MyAppDevelopment;
endpointRequest.token = [个体经营deviceTokenAsString:deviceToken]。
[[[SNS createPlatformApplication:endpointRequest] continueWithSuccessBlock:^ ID(AWSTask *任务){
AWSSNSCreateEndpointResponse *响应= task.result;
AWSSNSSubscribeInput * subscribeRequest = [AWSSNSSubscribeInput新]
subscribeRequest.endpoint = response.endpointArn;
subscribeRequest.protocols = @应用程序;
subscribeRequest.topicArn = @ARN:AWS:SNS:美国东部-1:753780999999:MyAppDevelopingTest;
返回[SNS订阅:subscribeRequest]。
}] continueWithBlock:^ ID(AWSTask *任务){
如果(task.cancelled){
的NSLog(@任务取消);
}
否则,如果(task.error){
的NSLog(@错误发生:[%@],task.error);
}
其他 {
的NSLog(@成功);
}
回零;
}];
但我得到的错误:
发生错误:错误域= com.amazonaws.AWSSNSErrorDomain code = 0的操作无法完成(com.amazonaws.AWSSNSErrorDomain错误0。)检测到的UserInfo = 0x17ee0950 {类型=发件人,邮件= 3验证错误:在名称值null未能满足约束条件:成员不能为null;在属性null值未能满足约束条件:成员不能为null;在平台价值空未能满足约束条件:成员不能为空,__TEXT =(
\ N,
\ N,
\ N,
\ N
),code = ValidationError}]
为什么要这样呢?为什么应用程序后,资源剪切/那是正确的?除了这个我不明白的地方我应该把deviceToken? 我真的需要帮助!在此先感谢?
我的Cognito作用是:
{
版本:2012年10月17日,
声明: [
{
效果:允许,
行动: [
SNS:CreatePlatformEndpoint
SNS:订阅,
SNS:CreatePlatformApplication
SNS:*
]
资源:
阿尔恩:AWS:SNS:*
]
}
]
}
我公司采用最新的AWS SDK:
安装AWSCognito 2.2.1(是2.2.0)
安装AWSCore 2.2.1(是2.2.0)
安装AWSSNS 2.2.1(是2.2.0)
抱歉,不幸的是你复制code,其中包括一个错字:
createPlatformApplication:endpointRequest
应该是:
createPlatformEndpoint:endpointRequest
该方法CreatePlatformApplication是不是在你原有的政策允许的。一旦你允许的SNS:*,呼叫被允许通过该服务,但该请求未包括所需要的参数CreatePlatformApplication,因此ValidationError。在您的原始邮件的修剪ARN也是缺乏CreatePlatformApplication参数的结果。
First of all I found the same question here, but it doesn't work... Maybe AWS SDK changes or something else, I don't know why... I want to subscribe to SNS topic from my iOS app. I am trying to do it with code from that answer, which I tried to change to get rid of errors:
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;
}];
But I get the error:
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}]
Why so? Why does the resource cut after app/ is it ok? Beside this I don't understand where I should put deviceToken? I really need help! Thanks in advance?
My Cognito role is:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sns:CreatePlatformEndpoint",
"sns:Subscribe",
"sns:CreatePlatformApplication",
"sns:*"
],
"Resource": [
"arn:aws:sns:*"
]
}
]
}
I am using the latest 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)
Sorry, unfortunately you copied code that included a typo:
createPlatformApplication:endpointRequest
Should be:
createPlatformEndpoint:endpointRequest
The method CreatePlatformApplication was not allowed in your original policy. Once you allowed sns:*, the call was allowed by the service, but the request didn't include the required parameters for CreatePlatformApplication, hence the ValidationError. The trimmed ARN in your original message is also a result of lack of parameters for CreatePlatformApplication.
这篇关于亚马逊AWS SNS:我如何订阅SNS主题从iOS的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!