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 ;
}
Your design is incorrect.
AFHTTPRequestOperationis 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 theAFHTTPRequestOperation.