简体   繁体   English

ASIDownLoadCache不起作用

[英]ASIDownLoadCache doesn't work

 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];

this is my code about http and if i turn my phone to fly model. 这是我关于http的代码,如果我将手机转为飞行模型。 i got this 我懂了

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}

The error you've posted means that the crash was from a connection failure, which makes sense if you have airplane mode enabled. 您发布的错误表示崩溃是由连接故障引起的,如果启用了飞行模式,这是有道理的。 You should be able to eliminate this be setting a failure handler. 您应该能够通过设置故障处理程序来消除这种情况。

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

Or 要么

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

To access cached data without internet access simply add the following to your request. 要访问没有互联网访问的缓存数据,只需将以下内容添加到您的请求中即可。

    [request setCachePolicy:ASIFallbackToCacheIfLoadFailsCachePolicy];

In order for this to work you need to make sure that cache storage is set to permanent to prevent the caches from being removed when the user exists the app. 为了使它起作用,您需要确保将缓存存储设置为永久性,以防止在用户存在应用程序时删除缓存。

    [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM