2

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失败,我如何重试而不崩溃?

4

1 回答 1

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];
于 2012-09-19T14:28:40.500 回答