我想在一个dispatch_group_asyc
块中执行一些网络调用时显示一个活动指示器。但活动指示器仅在块完成时显示。我正在创建一个dispatch_group_t
,因为我需要在执行其他一些任务之前获得网络调用的结果。这是我的代码的简化版本:
- (BOOL)doNetCall
{
[activityIndicator startAnimating];
__block BOOL netResult = NO;
dispatch_queue_t queue = dispatch_queue_create(netQueue, NULL);
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group,queue,^{
netResult = [service queryService];
});
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
dispatch_release(group);
dispatch_release(queue);
[activityIndicator stopAnimating];
if (netResult) {
// Perform some tasks
}
else {
[self showAlertView];
}
return netResult;
}
我究竟做错了什么?谢谢!
编辑:我需要该方法等到块完成才能返回我得到的结果