识别NSURLConnection中的瞬态错误

时间:2015-09-16 10:34:51

标签: objective-c error-handling foundation

情境:

我正在尝试使用NSURLConnection从云存储提供程序(Azure Blob-Storage或Amazon S3)异步检索文件。

我的想法是实现NSURLConnectionDelegate:

-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    // Check if the error code is transient 
    if([self checkIsTransientError:error])
    {
        // Create a new NSUrlConnection and re-try the call.

    }
    else
    {
        // The error is permanent, notify the UI that the file isn't there

    } 
}

当然,我的代码中会有很多其他不错的技巧,比如最大重试次数和指数后退......但是我将伪代码保留为简单,因为它需要说明我的代码。问题

问题:

什么错误代码被认为是暂时的?

到目前为止,我想出了一个(简短的)可能性列表:

  • HTTP状态500
  • 没有网络连接(由于网络不良)
  • 超时
  • CannotFindHost(DNSError)

更新:我终于找到了NSURLError中定义的所有大量可能错误代码的文档

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/#//apple_ref/doc/constant_group/URL_Loading_System_Error_Codes

所以我现在有一个很长的阅读时间,所以我可以决定哪个应该被视为我的应用程序的瞬态。

注意:我不想在项目中加入AFNetworking或其他漂亮的框架,只是为了不必进行瞬态检查。

0 个答案:

没有答案
相关问题