I am attempting to load a collection of objects via RestKit and have found that this operation is blocking the main thread. Specifically, this functionality is called when a UIViewController appears in the -(void)viewDidAppear:(BOOL)animated; message. As long as request is loading, the user is unable to interact with the UI, and has to wait until the operation has completed.
How can I instruct RestKit to execute the request asynchronously (I thought it already was) and stop blocking the main thread?
-(void)rtrvArtistsByStudio:(ISStudio *)studio
{
NSLog(@"Retrieving Artists for studio %ld", [studio studioID]);
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
NSDictionary *params = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%ld", [studio studioID]] forKey:@"studioID"];
NSURLRequest *request = [restkit requestWithObject:nil method:RKRequestMethodGET path:@"/restAPI/rtrvArtistsByStudio" parameters:params];
RKManagedObjectRequestOperation *operation = [restkit managedObjectRequestOperationWithRequest:request managedObjectContext:restkit.managedObjectStore.persistentStoreManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSArray *artists = [mappingResult array];
[studio setArtists:artists];
[notificationCenter postNotificationName:nStudioLoadedArtists object:studio];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed to load artists for studio %ld due to %@", [studio studioID], error);
[notificationCenter postNotificationName:nStudioFailedLoadingArtists object:studio];
}];
[restkit enqueueObjectRequestOperation:operation];
}
EDIT:
I should also note that restkit is a pointer to an instance of RKObjectManager.
RestKit version is 0.20
Turns out that it was actually my own fault (of course). I have a
UIViewControllercategory that performs some transitions. During the transition I have theUIApplicationignore touch events until the transition has completed (0.2s, very brief). I completely forgot that this existed.Because I am loading some remote objects in
viewDidAppearit was still ignoring touch events until that completed. Removing the touch ignore fixed the problem.