【发布时间】:2016-01-12 09:17:57
【问题描述】:
看来这应该比较简单。我正在使用适用于 iOS 的 AWS 开发工具包 (v2),我正在尝试下载 .png 文件并将其显示在 UIImage 中的屏幕上。一切确实有效!只是很奇怪...
这是我的代码:
AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:@"MY_ACCESS_KEY" secretKey:@"MY_SECRET_KEY"];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSWest1 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
AWSS3 *transferManager = [[AWSS3 alloc] initWithConfiguration:configuration];
AWSS3GetObjectRequest *getImageRequest = [AWSS3GetObjectRequest new];
getImageRequest.bucket = @"MY_BUCKET";
getImageRequest.key = @"MY_KEY";
[[transferManager getObject:getImageRequest] continueWithBlock:^id(BFTask *task) {
if(task.error)
{
NSLog(@"Error: %@",task.error);
}
else
{
NSLog(@"Got image");
NSData *data = [task.result body];
UIImage *image = [UIImage imageWithData:data];
myImageView.image = image;
}
return nil;
}];
当这段代码被执行时, continueWithBlock 被执行,没有任务错误,所以 Got image 被记录下来。这发生得相当快。然而,直到大约 10 秒后 UIImageView 才在屏幕上更新。我什至通过调试器来查看NSLog(@"Got image"); 行之后的任何行是否花费了很长时间,而事实并非如此。它们都执行得非常快,但是 UIImageView 不会在 UI 上更新。
【问题讨论】:
标签: ios amazon-web-services amazon-s3