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

たとえば、RKRequestDelegate プロトコルを使用して、RKRequest へのアクセスを試みることができます。

- (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 に答える