AWS 推送通知服务集成错误
Posted
技术标签:
【中文标题】AWS 推送通知服务集成错误【英文标题】:AWS push notification service integration error 【发布时间】:2015-06-26 04:03:37 【问题描述】:我正在尝试将亚马逊推送通知集成到我的 iPhone 应用程序中。我确实按照此处提供的教程正确操作。
创建平台端点时出现此错误。 (好像是身份池的权限问题???)
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;
];
【问题讨论】:
您确定可以使用常量“SNSPlatformApplicationArn
”吗?当我查看platformApplicationArn
的描述时,它显示“从 CreatePlatformApplication 返回的 PlatformApplicationArn 用于创建端点。”
【参考方案1】:
问题出在 AWS SNS 配置中。我们需要将“SNS:CreatePlatformEndpoint”添加到 Auth 和 Unauth 角色的策略中
【讨论】:
您介意详细说明一下您是如何解决这个问题的吗?我假设您的意思是您在 IAM 控制台中通过将自定义策略附加到 cognito unauth 角色来解决此问题,并且必须使用操作 sns:CreatePlatformEndpoint 手动生成该策略,如docs.aws.amazon.com/sns/latest/dg/… 中所述?我很难找到像样的文档,但总的来说我对 IAM 政策有点生疏。既然你说你在 SNS 配置中修复了它,我只是好奇是否有更快的方法来添加所需的策略。 您还需要在策略中添加资源 ARN。 谢谢!也修复了它,只需进入 IAM 管理控制台并查找正确的策略并添加 SNS:CreatePlatformEndpoint。 检查文档我看不到 SNS:CreatePlatformEndpoint ...知道现在是否有等价物?【参考方案2】:您可以在Roles
下添加AmazonSNSFullAccess
->attach policy
。
【讨论】:
以上是关于AWS 推送通知服务集成错误的主要内容,如果未能解决你的问题,请参考以下文章
如何将 React 本机导航与 Android 中的 AWS Amplify 推送通知集成?