Reputation: 159
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}
Upvotes: 0
Views: 301
Reputation: 130192
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];
Upvotes: 1