【问题标题】:Detect Time Out Error With AFNetworking使用 AFNetworking 检测超时错误
【发布时间】:2014-11-09 12:29:34
【问题描述】:

我使用AFNetworking 从我的 Web 服务中检索数据,一切正常,但我想检测超时错误。我在请求的失败块中使用了这段代码,但我不工作

failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    if ([operation.response statusCode] == 408) {
      //time out error here
    }
}];

代码408是正常的超时错误

【问题讨论】:

    标签: ios objective-c timeout afnetworking


    【解决方案1】:

    由于 AFNetworking 是在 NSULConnection/NSULRSession 之上构建的,因此您只需 NSURLErrorTimedOut 即可检查错误是否为超时错误:

     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    
        if (error.code == NSURLErrorTimedOut) {
          //time out error here
        }
    }];
    

    你在哪里检查 HTTP 状态码,但是由于连接超时,所以没有状态码。

    【讨论】:

      猜你喜欢
      • 2012-08-05
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      相关资源
      最近更新 更多