0
我正在異步運行AFNetworking。見下面的代碼。AFNetworking同步運行
我想同步運行它做一個軟件包下載(我需要獲得人們可以選擇的服務列表)。我怎樣才能做到這一點?
謝謝。
NSMutableURLRequest *apiRequest =
[self multipartFormRequestWithMethod:@"POST"
path: pathstr
parameters: params
constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
{
//TODO: attach file if needed
}];
AFJSONRequestOperation* operation = [[AFJSONRequestOperation alloc] initWithRequest: apiRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//success!
completionBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//failure :(
NSLog(@"%@", error);
completionBlock([NSDictionary dictionaryWithObject:[error localizedDescription] forKey:@"error"]);
}];
[operation start];
看看AFNetworking的創造者Mattt的這篇文章。 http://stackoverflow.com/questions/7969865/can-afnetworking-return-data-synchronously-inside-a-block/7970037#7970037 –