Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 851
anticyclope Avatar asked Jul 27 '26 01:07

anticyclope


1 Answers

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.

like image 169
lawicko Avatar answered Jul 29 '26 16:07

lawicko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!