iphone - ASIDownLoadCache 不起作用

标签 iphone objective-c ios ipad asihttprequest

 ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:url]];
request.requestHeaders = header;
request.requestMethod = @"GET";
request.tag = DBRequestTypeChannelCategory;
[request setDelegate:self];
[request setNumberOfTimesToRetryOnTimeout:2];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request setCachePolicy:ASIFallbackToCacheIfLoadFailsCachePolicy];
[request setSecondsToCache:60*60*24*3];
[request startAsynchronous];

这是我关于http的代码 如果我 Handlebars 机调成飞行模式。 我得到了这个

Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x1fd67bf0 {NSUnderlyingError=0x1fd66bf0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)", NSLocalizedDescription=A connection failure occurred}

最佳答案

您发布的错误意味着崩溃是由于连接故障造成的,如果您启用了飞行模式,则这是有意义的。您应该能够通过设置故障处理程序来消除这种情况。

    [request setFailedBlock:void^{
        //
    }];

或者

    [request setDidFailSelector:@selector(requestWentWrong:)];

要在无需访问互联网的情况下访问缓存数据,只需将以下内容添加到您的请求中即可。

    [request setCachePolicy:ASIFallbackToCacheIfLoadFailsCachePolicy];

为了使其正常工作,您需要确保缓存存储设置为永久,以防止在用户存在应用程序时删除缓存。

    [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];

关于iphone - ASIDownLoadCache 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13065046/

相关文章:

iphone - iOS (iPhone) 开发 - 本地通知在应用程序未运行时随机触发

ios - 警报后打开一个新的 View Controller

ios - 强制按钮看起来被按下?

iphone - 错误:使用FBConnect在Facebook上发布图片

iphone - 从 superView 中删除 UIView

ios - 具有负 M_PI 的 CGAffineTransformMakeRotation

ios - Swift/Watchkit 中涉及字符串的函数问题

iphone - 可以在MKMapView上绘制的最大注释数(MKAnnotation)?

ios - 如果应用程序第二次运行,从 executeFetchRequest 返回的记录为空

ios - iPhone SDK 网络连接检测