如何在 Objective-c 中实现对 AWS DynamoDB 的同步访问?
我理解了使用 Bolts BFTask 对 DynamoDB 的异步访问,如下所示,但我需要“同步”连接。
----添加了一些信息----
我在“DynamoQuery”类中调用了“ddbIDQuery”方法,但它返回(null),因为 Bolts 异步事务?获得结果的最佳方法是什么?
// MainViewController.m
#import "DynamoQuery.h"
-(IBAction)ddqButton:(UIButton *)sender
{
// call DynamoQuery
DynamoQuery *dynamoQuery = [[DynamoQuery alloc] init];
NSLog(@"dynamoQuery: %@", [dynamoQuery ddbIDQuery:@"448898329-6BC0FA0A954913043A3281599A444E3C"]);
}
// DynamoQuery.m
- (NSString *) ddbIDQuery: (NSString*)ddbID
{
__block NSString *strpid = nil;
AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
[[dynamoDBObjectMapper load:[PIDTable class] hashKey:ddbID rangeKey:nil] continueWithBlock:^id(AWSTask *task)
{
NSLog(@"ddbID: %@", ddbID);
if (task.error){
NSLog(@"The 1st request failed. Error: [%@]", task.error);
}
if (task.exception) {
NSLog(@"The 1st request failed. Exception: [%@]", task.exception);
}
if (task.result) {
PIDTable *ddbpid = task.result;
NSData *datapid = [ddbpid.text dataUsingEncoding:NSUTF8StringEncoding];
strpid = [[NSString alloc] initWithData:datapid encoding:NSUTF8StringEncoding];
};
return nil;
}
];
return strpid;
}