RestKit:如何重试失败的请求?

时间:2012-08-28 04:12:28

标签: ios restkit

如果他们失败,我正在尝试让我的应用重试RKRequests。我试着这样做:

- (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失败,如何在不崩溃的情况下重试?

1 个答案:

答案 0 :(得分:0)

您可以尝试访问RKRequest,例如使用RKRequestDelegate协议:

- (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error

因为那样你就可以做到以下几点:

NSAssert(!request.isUnsent && !request.isLoading, @"Cant retry load, current attempt has not completed");
[request reset];
[request send];