0
votes
  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.

2

2 Answers

1
votes

You should upgrade to the latest (or at least not a pre) version of RestKit.

Generally, your code looks fine and you should be able to make multiple concurrent requests. You should set the maximum number of concurrent operations on objectManager.operationQueue to around 5 though or you may flood the system and all requests will timeout.

0
votes

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