Reputation: 3969
I am running AFNetworking asynchronously. See code below.
I want to run it synchronously to do a package download (I need to get the list of services that people will be able to choose from). How can I do this?
Thanks.
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];
Upvotes: 0
Views: 3327
Reputation: 69047
I want to run it synchronously to do a package download (I need to get the list of services that people will be able to choose from). How can I do this?
AFNetworking does not support sync operations.
On the other hand, you almost never want sync operations on your UI thread, because the UI would become unresponsive.
(I need to get the list of services that people will be able to choose from)
What you could do is displaying some UI hint that the list of services is being downloaded while the async operation is in progress.
Upvotes: 1