0
我試圖得到S3TransferUtilitySampleObjC項目,我Cognito和AWS憑據工作。AWS/iOS版/ Cognito:未經驗證的訪問不支持這個身份池
不幸的是我得到的錯誤如下:
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一些代碼,修改常量的值 - 我還修改了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用戶?我們已經創建了聯邦身份驗證測試用戶。對不起,這個跛腳的問題,只是試圖獲得第一步。 – mm24
哦,別擔心!經過身份驗證的用戶只是指已登錄某個身份提供者的用戶,該用戶也爲該遊戲池(即Facebook,Google,Twitter或鏈接的用戶池)進行了配置。你可能會設置取決於應用程序的需求,但有樣品,可以告訴你如何使用各種供應商:https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoSync-Sample –
好。感謝您的鏈接。我想我可能會要求禁用該功能。所以基本上支持第三方提供商的重點是增加安全性。我正在開發的應用程序僅供內部使用,所以我可能不需要第一個版本。非常感謝解釋。 – mm24