Skip to content

Instantly share code, notes, and snippets.

@baarde
Last active October 7, 2017 20:05
Show Gist options
  • Save baarde/46f3c9cb3c56927b1356 to your computer and use it in GitHub Desktop.
Save baarde/46f3c9cb3c56927b1356 to your computer and use it in GitHub Desktop.
How to use AFNetworking synchronously
#import "AFNetworking.h"
int main(void)
{
NSURL *baseURL = [NSURL URLWithString:@"http://graph.facebook.com/"];
AFHTTPRequestOperationManager *operationManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];
AFHTTPRequestOperation *operation = [operationManager GET:@"Octiplex" parameters:nil success:nil failure:nil];
[operationManager.operationQueue waitUntilAllOperationsAreFinished];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate date]]; // Executes async notification blocks waiting in the main queue
NSLog(@"Response: %@", operation.responseObject);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment