0

我似乎无法理解如何最好地处理几个 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 支持网站上问过这个问题。

4

1 回答 1

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 存储库对如何使用 Bolts 有很好的说明。

希望这可以帮助,


更新

适用于 iOS 2.0.4 的 AWS 移动开发工具包已发布。该更新解决了这个问题,现在它返回了正确的locationConstraint.

于 2014-07-18T00:26:02.397 回答