![](/img/trans.png)
[英]AWS Cognito: “Unauthenticated access is not supported for this identity pool.”
[英]AWS / iOS / Cognito: unauthenticated access is not supported for this identity pool
我正在尝试使S3TransferUtilitySampleObjC项目与我的Cognito和AWS凭证一起使用。
不幸的是,我得到以下错误:
AWSURLSessionManager.m line:566 | -[AWSURLSessionManager printHTTPHeadersForResponse:] | Response headers:
{
Connection = "keep-alive";
"Content-Length" = 111;
"Content-Type" = "application/x-amz-json-1.1";
Date = "Mon, 16 Jan 2017 17:17:50 GMT";
"x-amzn-ErrorMessage" = "Unauthenticated access is not supported for this identity pool.";
"x-amzn-ErrorType" = "NotAuthorizedException:";
"x-amzn-RequestId" = "xxxxxxxxx-xxxxx-xxxxx-xxxx-xxxxxxx";
}
你能帮忙吗?
代码(请注意,我仅从SecondViewController中删除了一些代码并修改了Constants中的值-我还修改了Info.plist文件(请参见下面的屏幕截图)
我目前只专注于从S3存储桶下载文件 。 因此,我仅修改了以下内容:
// In Constants.m
NSString *const S3BucketName = @"mybucketname";
NSString *const S3DownloadKeyName = @"config.plist";
// In SecondViewController.m
#import "SecondViewController.h"
#import "AppDelegate.h"
#import <AWSS3/AWSS3.h>
#import "Constants.h"
@interface SecondViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (copy, nonatomic) AWSS3TransferUtilityDownloadCompletionHandlerBlock completionHandler;
@property (copy, nonatomic) AWSS3TransferUtilityProgressBlock progressBlock;
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.progressView.progress = 0;
self.statusLabel.text = @"Ready";
__weak SecondViewController *weakSelf = self;
self.completionHandler = ^(AWSS3TransferUtilityDownloadTask *task, NSURL *location, NSData *data, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
weakSelf.statusLabel.text = @"Failed to Download";
}
if (data) {
weakSelf.statusLabel.text = @"Successfully Downloaded";
weakSelf.imageView.image = [UIImage imageWithData:data];
weakSelf.progressView.progress = 1.0;
}
});
};
self.progressBlock = ^(AWSS3TransferUtilityTask *task, NSProgress *progress) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.progressView.progress = progress.fractionCompleted;
});
};
AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
[transferUtility enumerateToAssignBlocksForUploadTask:nil downloadTask:^(AWSS3TransferUtilityDownloadTask * _Nonnull downloadTask, AWSS3TransferUtilityProgressBlock _Nullable __autoreleasing * _Nullable downloadProgressBlockReference, AWSS3TransferUtilityDownloadCompletionHandlerBlock _Nullable __autoreleasing * _Nullable completionHandlerReference) {
NSLog(@"%lu", (unsigned long)downloadTask.taskIdentifier);
*downloadProgressBlockReference = weakSelf.progressBlock;
*completionHandlerReference = weakSelf.completionHandler;
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Uploading...";
});
}];
}
- (IBAction)start:(id)sender {
self.imageView.image = nil;
AWSS3TransferUtilityDownloadExpression *expression = [AWSS3TransferUtilityDownloadExpression new];
expression.progressBlock = self.progressBlock;
AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
[[transferUtility downloadDataFromBucket:S3BucketName
key:S3DownloadKeyName
expression:expression
completionHander:self.completionHandler] continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(@"Error: %@", task.error);
}
if (task.exception) {
NSLog(@"Exception: %@", task.exception);
}
if (task.result) {
dispatch_async(dispatch_get_main_queue(), ^{
self.statusLabel.text = @"Downloading...";
});
}
return nil;
}];
}
在以下位置修改了Info.plist文件:
您收到的错误说明了这个问题-您正在以未经身份验证的用户身份向Cognito发送请求,这意味着没有为该身份包含/链接任何登录名,但未为该池启用该登录名。
未经身份验证的身份是身份池的可选功能,您必须在通过Cognito控制台创建/编辑池时将其启用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.