anticyclope
anticyclope

Reputation: 1587

RestKit: requeue RKRequest in RKRequestQueue

I'm trying to implement an upload queue in my application. I'm putting my RKRequests into RKRequestQueue and call [queue start]. But, as we all know, network connection is something that is not lasts forever. I'm using RKReachabilityObserver now to determine when to suspend and resume my queue, and it is working fine (at least now, however I've heard about some issues with reachability code in RestKit). This lets me to stop sending new data until network is available again. But when network connection is lost, all active RKRequests are issuing - (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error where, I thought, I will be able to put my RKRequest back in queue again.

So, I tried this:

- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error
{
    NSLog(@"Request failed");
    [[request queue] cancelRequest:request];
    [[request queue] addRequest:request];
}

but I'm getting an EXC_BAD_ACCESS somewhere in didFailLoadWithError method of RKRequest.

My question is: how can I requeue a RKRequest?

Upvotes: 3

Views: 1097

Answers (1)

lawicko
lawicko

Reputation: 7344

Instead of cancelling and adding to queue, do:

[request send];

But the best solution for this would really be to use RKClient, it makes things easier. You would not have to worry about queue. The client comes with and instance of RKRequestQueue and does all the magic behind the scenes, specifically it adds all requests configured for the given client to the clients request queue and dispatches them for you.

Upvotes: 1

Related Questions