【问题标题】:Restkit: Retry failed requestRestkit:重试失败的请求
【发布时间】:2013-01-14 16:23:36
【问题描述】:

使用 Restkit,我想重试失败的请求。我正在尝试从委托方法执行此操作,如下所示:

-(void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error{
    NSLog(error.domain);
    NSLog([NSString stringWithFormat:@"%d",error.code]);
    NSLog(error.localizedDescription);
    NSLog(error.localizedFailureReason);
    [request cancel];
    [request reset];
    [request send];
}

但是,我收到以下错误:

2013-01-14 11:19:29.423 Mobile_ACPL[7893:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to add the same request multiple times'

我怎样才能做到这一点?

【问题讨论】:

    标签: ios web-services delegates restkit


    【解决方案1】:

    错误消息暗示您尝试(重新)发送的request 仍在某些内部队列中。可能给系统更多时间来处理cancelreset 可以使事情正常进行。

    试试这个:

    -(void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error{
    
      [request cancel];
      [request reset];
    
      dispatch_async(dispatch_get_current_queue(), ^() {
          [request send];
      }
    }
    

    希望对您有所帮助。如果这不起作用,那么可能会延迟一点(重新)发送可能会有所帮助。这相当于做(延迟 1.0 秒):

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 1.0),
                   dispatch_get_current_queue(),  ^() {
          [request send];
      });
    

    或者完全提出请求的copy 并发送。

    【讨论】:

    • 请注意,自 iOS 6.0 起,dispatch_get_current_queue() 已被弃用
    猜你喜欢
    • 2016-02-25
    • 2013-06-25
    • 1970-01-01
    • 2018-02-20
    • 2015-09-09
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 2016-04-27
    相关资源
    最近更新 更多