2
我試圖讓我的應用程序重試RKRequests
,如果它們失敗。我試圖做這種方式:RestKit:如何重試失敗的請求?
- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)errorIn
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.waitView stop];
NSInteger code = objectLoader.response.statusCode;
if (201 != code && 200 != code)
{
// determine whether to requeue the request or not
if ([objectLoader.userData isEqualToString:@"capture"]) // requeue captures
{
NSLog(@"requeueing request");
[objectLoader.queue cancelRequest:objectLoader];
[objectLoader send];
}
}
}
...但它總是崩潰,因爲objectLoader
似乎是cancelRequest
線後懸擺指針。如果RKRequest
發生故障,我如何在不崩潰的情況下重試它?
當我嘗試這一點,斷言總是熄滅,因爲request.isLoading仍設置爲true。如果我將斷言註釋掉,我會在[請求發送]中得到「無法多次添加相同的請求」錯誤。如果我做[請求sendAsynchronously],請求立即失敗。爲什麼要讓RestKit做一個簡單的重試是非常困難的? –
您是否嘗試手動取消請求?然後斷言不應該失敗。 – Nicholas