【发布时间】:2012-11-25 23:02:33
【问题描述】:
我正在异步运行 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 的这篇文章。 stackoverflow.com/questions/7969865/…
标签: ios cocoa-touch ios5 ios4 afnetworking