I am currently migrating a project that used ASIHTTPRequest and SBJson to RestKit.
The previous implementation was using an NSOperation to make the HTTP Request, parse the JSON object and make the necessary calls to the Core Data API.
I have re-factored this as follows:
@implementation UpdateBeers
#pragma mark - NSOperation
- (void)main {
[[RKClient sharedClient] get:@"/beers" delegate:self];
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
debug(@"didLoadResponse");
}
- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error {
debug(@"%@", error);
}
#pragma mark - Memory
- (void) dealloc {
[super dealloc];
}
@end
The following appears in the log
sending GET request to URL http://localhost:9091/api/test. HTTP Body:
The problem is the server never receives the request.
Adding the following line :
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.3]];
to the end of the main method solves this problem.
My question is :
Should I be executing ResKit API calls as an NSOperation and if not what are my alternatives for making calls in the background?
Thanks in advance.