Search code examples
restkitnsurlrequestnsoperationqueuerestkit-0.20

RestKit 0.22.0: each -[getObject] call cancels previous one (error -999)


  1. First, getObject with a list of IDs.
  2. Then, use those IDs for multiple getObjects calls.

The problem is that any one of those multiple getObject gets cancelled (error -999).

RKObjectManager *objectManager = [RKObjectManager sharedManager];

- (void)firstGetListOfIDs 
{
    A *a = [A new];
    [objectManager getObject:a
                        path:nil
                  parameters:parameters
                     success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                         for (NSString* anID in a.listOfIDs)
                             [self thenGetObjectForID:anID];
                     } failure:nil];
}

- (void)thenGetObjectForID:(NSString*)anID
{
    B *b = [B new];
    [objectManager getObject:b
                        path:nil
                 parameters:parametersWithAnID
                    success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                 } failure:nil];
}

That is, each getObject call (in thenGetObjectForID: above) errors on lines 211 and 552 in RKObjectRequestOperation.m:

E restkit.network:RKObjectRequestOperation.m:211 GET 'http://domain.com/sdk/b?id=anID' (0 / 0 objects) [request=0.0000s mapping=0.0000s total=0.0006s]: Cancelled

E restkit.network:RKObjectRequestOperation.m:552 Object request failed: Underlying HTTP request operation failed with error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x134772e0 {NSErrorFailingURLKey=http://domain.com/sdk/b?id=anID}

Now, I can remedy this by adding [objectManager.operationQueue waitUntilAllOperationsAreFinished]; but, alas this blocks the main thread. How to make multiple, asynchronous getObject requests?

I've tried using RKObjectManager's enqueueBatchOfObjectRequestOperations:progress:completion:, though not sure if properly.


Solution

  • The culprit turned out to be a vagabond [[RKObjectManager sharedManager] cancelAllObjectRequestOperationsWithMethod:matchingPathPattern:]; call.