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的代码 如果我把我的手机转为飞行模型。 我得到了这个
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}
答案 0 :(得分:1)
您发布的错误意味着崩溃来自连接失败,如果您启用了飞行模式,这是有意义的。您应该能够消除这种情况,设置故障处理程序。
[request setFailedBlock:void^{
//
}];
或者
[request setDidFailSelector:@selector(requestWentWrong:)];
要访问没有互联网访问权限的缓存数据,只需将以下内容添加到您的请求中即可。
[request setCachePolicy:ASIFallbackToCacheIfLoadFailsCachePolicy];
为了使其正常工作,您需要确保将缓存存储设置为永久性,以防止在用户存在应用程序时删除缓存。
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];