首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >AWS推送通知服务集成错误

AWS推送通知服务集成错误
EN

Stack Overflow用户
提问于 2015-06-26 12:03:37
回答 2查看 5.8K关注 0票数 18

我正在尝试将亚马逊推送通知集成到我的iPhone应用程序中。我确实正确地遵循了这里提供的教程。

我在创建平台EndPoint时遇到此错误。(似乎是身份池的权限问题?)

CognitoIdentityCredentials is not authorized to perform: SNS:CreatePlatformEndpoint

完整消息:

Error: Error Domain=com.amazonaws.AWSSNSErrorDomain Code=4 "The operation couldn’t be completed. (com.amazonaws.AWSSNSErrorDomain error 4.)" UserInfo=0x165dcef0 {Type=Sender, Message=User: arn:aws:sts::290442422498:assumed-role/Cognito_Laugh_DevUnauth_Role/CognitoIdentityCredentials is not authorized to perform: SNS:CreatePlatformEndpoint on resource: arn:aws:sns:us-east-1:290442422498:app/APNS_SANDBOX/Laugh, __text=(
"\n    ",
"\n    ",
"\n    ",
"\n  "
), Code=AuthorizationError}

代码

AWSRegionType const CognitoRegionType = AWSRegionUSEast1;
AWSRegionType const DefaultServiceRegionType = AWSRegionUSEast1;
NSString *const CognitoIdentityPoolId = @"us-east-1:0..................";
NSString *const SNSPlatformApplicationArn = @"arn:aws:sns:us-east-1:................";
NSString *const MobileAnalyticsAppId = @"YourMobileAnalyticsAppId";


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  // Sets up the AWS Mobile SDK for iOS
 AWSCognitoCredentialsProvider *credentialsProvider =   [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoRegionType identityPoolId:CognitoIdentityPoolId];

 AWSServiceConfiguration *defaultServiceConfiguration = [[AWSServiceConfiguration alloc] initWithRegion:DefaultServiceRegionType
                                                                                   credentialsProvider:credentialsProvider];

 AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = defaultServiceConfiguration;
}


- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{

NSString *deviceTokenString = [[[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]] stringByReplacingOccurrencesOfString:@" " withString:@""];

NSLog(@"deviceTokenString: %@", deviceTokenString);
[[NSUserDefaults standardUserDefaults] setObject:deviceTokenString forKey:@"deviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];

AWSSNS *sns = [AWSSNS defaultSNS];
AWSSNSCreatePlatformEndpointInput *request = [AWSSNSCreatePlatformEndpointInput new];
request.token = deviceTokenString;
request.platformApplicationArn = SNSPlatformApplicationArn;

NSLog(@"SNSPlatformApplicationArn %@", SNSPlatformApplicationArn);

[[sns createPlatformEndpoint:request] continueWithBlock:^id(BFTask *task) {
    if (task.error != nil) {
        NSLog(@"Error: %@",task.error);
    } else {
        AWSSNSCreateEndpointResponse *createEndPointResponse = task.result;
        NSLog(@"endpointArn: %@",createEndPointResponse);
        [[NSUserDefaults standardUserDefaults] setObject:createEndPointResponse.endpointArn forKey:@"endpointArn"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        //[self.window.rootViewController.childViewControllers.firstObject performSelectorOnMainThread:@selector(displayDeviceInfo) withObject:nil waitUntilDone:NO];

    }

    return nil;
}];

}

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-29 13:57:34

问题出在AWS SNS配置中。我们需要将"SNS:CreatePlatformEndpoint“添加到身份验证和取消身份验证角色的策略中

票数 18
EN

Stack Overflow用户

发布于 2016-04-29 21:00:47

您可以在Roles->attach policy下添加AmazonSNSFullAccess

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31064686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档