Restkit 0.24.1 POST到服务器并同步获取响应

时间:2015-10-20 12:00:18

标签: ios objective-c iphone restkit

有没有人知道如何同步接收发布数组的响应? 我在这里:

[manager postObject:objectArray path:@"" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
    NSLog(@"Loading mapping result: %@", result.firstObject);
    res = [NSMutableArray arrayWithArray:[result array]];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    if (operation.error) {...}

但我希望得到[result array];毫不拖延

1 个答案:

答案 0 :(得分:0)

如果您只想阻止当前线程

__block BOOL operationDone = NO;
[[RKObjectManager sharedManager] getObject:nil
                                      path:path
                                parameters:parameters
                                   success:^(RKObjectRequestOperation *operation, RKMappingResult *blockMappingResult) {

                                           // Do something

                                           operationDone = YES;
                                       }
                                   failure:^(RKObjectRequestOperation *operation, NSError *error) {

                                           // Do something

                                           operationDone = YES;
                                       }];

while(!operationDone) {
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}