Search code examples
objective-cpaginationrestkit

RKPaginator - no result - no error


I'm trying to use RKPaginator to collect an Array of results from my API.

Here is my code:

RKEntityMapping *commentMapping = [APICallComment RKGetCommentMappingForManagedObjectStore:self.appDelegate.managedObjectStore];

NSString * convertedPath = [APICallCommentListCommentsPattern stringByReplacingOccurrencesOfString:@":photoId"withString:[NSString stringWithFormat:@"%@",photoId]];

// Register our mappings with the provider
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:commentMapping
                                                                                            method:RKRequestMethodGET
                                                                                       pathPattern:convertedPath
                                                                                           keyPath:@"comments"
                                                                                       statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[self.session.objectManager addResponseDescriptor:responseDescriptor];
self.session.objectManager.requestSerializationMIMEType = RKMIMETypeJSON;

commentsPaginator = [self.session.objectManager paginatorWithPathPattern:[NSString stringWithFormat:@"%@%@", convertedPath,@"?per_page=:perPage&page=:currentPage"]];

commentsPaginator.perPage=ListCommentsNumberOfCommentsPerPage;

__weak typeof(self) weakSelf = self;
[commentsPaginator setCompletionBlockWithSuccess:^(RKPaginator *paginator , NSArray *comments , NSUInteger page) {

      //Code for success
    } failure:^(RKPaginator *paginator, NSError *error) {
      //Code for failure
    }];

My problem is that nothing happens. I'm waiting even for an error but I have nothing. My API doesn't receive anything. That means there is a problem during the compression block.

I've added these lines:

RKLogConfigureByName("*", RKLogLevelTrace);
RKLogConfigureByName("RestKit*", RKLogLevelTrace);

But there is still nothing. No error in both sides.

Thank you for your help.


Solution

  • You haven't called loadPage: anywhere, so you haven't asked for any download to happen.

    Also, the point of a path pattern is to be a pattern, so you might want to reconsider explicitly adding the id yourself and using that in the response descriptor (hote that I don't know enough to say that what you have is wrong and it could work just fine).