0
 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}
4

1 回答 1

1

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

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

或者

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

要在不访问 Internet 的情况下访问缓存数据,只需将以下内容添加到您的请求中。

    [request setCachePolicy:ASIFallbackToCacheIfLoadFailsCachePolicy];

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

    [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
于 2012-10-25T09:08:02.113 回答