Question

I am using Restkit in my iOS app to make a GET call to my server. I am able to get the call to work just fine, except that it is supposed to be asynchronous and it is blocking my main thread. I am basically using their exact sample to make the request from their github page which is as follows:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mywebapi.com/Article"]];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
    Article *article = [result firstObject];
    NSLog(@"Mapped the article: %@", article);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
[operation start];

This blocks all main thread executions (such as my transitions) until the success block is called. Wrapping this call inside of a dispatch_queue does resolve the issue, but it is my understanding that this method is supposed to be asynchronous on its own.

Am I missing some configuration on the RKObjectRequestOperation, or is there a different method I should be calling for an async call?

Was it helpful?

Solution

I found the answer to this question here:

RestKit Makes UI Unresponsive

Basically, you do need to add it to an NSOperationQueue, otherwise it will run the call on the main thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top