我似乎无法理解如何最好地处理几个AWS SDK iOS v2方法的 BFTask (Bolts框架)返回对象。我正在尝试获取我的存储桶所在区域的名称。有人建议如何根据我从以下代码成功接收的 locationConstraint 信息来做到这一点吗?或者有一种通用的方法来理解task.result对象包含的内容吗?
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
AWSS3 *myS3 = [[AWSS3 alloc] initWithConfiguration:self.configurationS3];
AWSS3GetBucketLocationRequest *locReq = [AWSS3GetBucketLocationRequest new];
locReq.bucket=@"testAWS";
[[myS3 getBucketLocation:locReq] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
if(task.error != nil){
NSLog(@"%s Location not found: [%@]",__PRETTY_FUNCTION__, task.error);
} else {
NSLog(@"Location found: [%@] - %li", task.result, [task.result locationConstraint]);
}
return nil;
}];
此外,如果有人对教程/示例提出建议,以便最好地理解BFTask,这将有所帮助。谢谢你的帮助。干杯,特隆德 PS。我还在AWS support site上提出了这个问题。
答案 0 :(得分:1)
以下是确定存储区位置的代码段:
AWSS3 *s3 = [AWSS3 defaultS3];
AWSS3GetBucketLocationRequest *getBucketLocationRequest = [AWSS3GetBucketLocationRequest new];
getBucketLocationRequest.bucket = testBucketNameGeneral;
[[s3 getBucketLocation:getBucketLocationRequest] continueWithBlock:^id(BFTask *task) {
if(task.error != nil){
XCTAssertNil(task.error, @"The request failed. error: [%@]", task.error);
}
AWSS3GetBucketLocationOutput *getBucketLocationOutput = task.result;
XCTAssertEqual(getBucketLocationOutput.locationConstraint, AWSS3BucketLocationConstraintBlank);
switch (getBucketLocationOutput.locationConstraint) {
case AWSS3BucketLocationConstraintBlank:
NSLog(@"Classic Region");
break;
case AWSS3BucketLocationConstraintEU:
NSLog(@"EU");
break;
case AWSS3BucketLocationConstraintEUWest1:
NSLog(@"eu-west-1");
break;
case AWSS3BucketLocationConstraintUSWest1:
NSLog(@"us-west-1");
break;
case AWSS3BucketLocationConstraintUSWest2:
NSLog(@"us-west-2");
break;
case AWSS3BucketLocationConstraintAPSoutheast1:
NSLog(@"ap-southeast-1");
break;
case AWSS3BucketLocationConstraintAPSoutheast2:
NSLog(@"ap-southeast-2");
break;
case AWSS3BucketLocationConstraintAPNortheast1:
NSLog(@"ap-northeast-1");
case AWSS3BucketLocationConstraintSAEast1:
NSLog(@"sa-east-1");
break;
case AWSS3BucketLocationConstraintUnknown:
default:
// Error
break;
}
return nil;
}];
但是,SDK中存在错误,getBucketLocationOutput.locationConstraint
始终为AWSS3BucketLocationConstraintUnknown
。我们正在努力修复此问题。
Bolts-iOS GitHub repo对如何使用螺栓有很好的指导。
希望这有帮助,
<强>更新强>
AWS Mobile SDK for iOS 2.0.4已发布。此更新修复了此问题,现在它返回正确的locationConstraint
。