【问题标题】:RestKit 0.27 - set a request timeoutRestKit 0.27 - 设置请求超时
【发布时间】:2017-06-20 18:21:57
【问题描述】:

我正在寻找一种在 RestKit v.0.27.0 中为基本 RKObjectManager getObjectsAtPath: parameters: success: failure: 请求设置请求超时的方法

现在,如果用户到达一个视图,触发了这个请求,然后他的互联网关闭了,什么都不会发生,它只会继续加载很长一段时间。如何手动将超时时间更改为某个时间(例如 15 秒)?

【问题讨论】:

    标签: restkit


    【解决方案1】:

    为了检测客户端的网络连接何时消失,苹果很久以前就发布了Reachability class。如果您不使用它,请随时使用this tutorial 快速入门。

    如教程中所述,您可以在可达性消失时做出响应,因此可以取消所有待处理的请求。

    - (void)reachabilityDidChange:(NSNotification *)notification {
        Reachability *reachability = (Reachability *)[notification object];
    
        if ([reachability isReachable]) {
            NSLog(@"Host is reachable");
        } else {
            NSLog(@"Host is unreachable");
    
            // Cancel all pending RestKit requests
            [[RKObjectManager sharedManager].operationQueue cancelAllOperations];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      相关资源
      最近更新 更多