简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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