如何在AFHTTPRequestOperation完成后使函数返回 [英] how to make function to return after the AFHTTPRequestOperation has done
本文介绍了如何在AFHTTPRequestOperation完成后使函数返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望函数在 AFHTTPRequestOperation
完成之前不会返回,但我不知道该怎么做,感谢提前。
I want the function do not return until the AFHTTPRequestOperation
finished, but I did not know how to do it, thanks in advance.
-(BOOL)download
{
BOOL ret = TRUE;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
ret = [self handle:data];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", error);
}];
[operation start];
return ret ;
}
推荐答案
您的设计不正确。
AFHTTPRequestOperation
是异步的,因此您不能(并且不应该)以同步方式处理它。您必须修改工作流程才能使用 AFHTTPRequestOperation
的完成或失败块。
AFHTTPRequestOperation
is asynchronous so you cannot (and you shouldn't) treat it in a synchronous way. You have to modify your workflow in order to use the completion or failure blocks of the AFHTTPRequestOperation
.
这篇关于如何在AFHTTPRequestOperation完成后使函数返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文