ASIHTTPRequest离线模式连接失败
我遇到了 ASIHTTPRequest 的问题,我尝试使用可用的 UIWebview 开发 iphone 应用程序当用户在没有网络的情况下启动它时。
这个库很完美,但是当我离线启动我的应用程序时出现错误。
Error Domain=ASIHTTPRequestErrorDomain Code=1 UserInfo=0x17bdb0 "A connection failure occurred"
我不知道为什么会发生这种情况,因为我启动了一次应用程序(这意味着缓存已下载),当我通过 SSH 进入 iPhone 的应用程序文件夹时,我可以看到所有缓存的数据。
那么为什么当我将 iPhone 设置为飞行模式时,我会收到此消息?
这是我发出请求的代码(非常简单):
NSURL *url = [NSURL URLWithString:@"http://mywebsite.com"];
[[self request] setDelegate:nil];
[[self request] cancel];
[self setRequest:[ASIWebPageRequest requestWithURL:url]];
[[self request] setShouldAttemptPersistentConnection:NO];
[[self request] setDelegate:self];
[[self request] setDidFailSelector:@selector(webPageFetchFailed:)];
[[self request] setDidFinishSelector:@selector(webPageFetchSucceeded:)];
[[self request] setUrlReplacementMode:ASIReplaceExternalResourcesWithData];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[[self request] setDownloadCache:[ASIDownloadCache sharedCache]];
[[self request] setDownloadDestinationPath:
[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:[self request]]];
[[self request] startAsynchronous];
我从 文档 中获取了示例,这就是为什么我不明白问题出在哪里。
感谢您的任何帮助。
I'm having an issue with ASIHTTPRequest, I try to develop an iphone app with an UIWebview which is usable when user launch it without network.
This library is perfect but I get an error when I launch my app offline.
Error Domain=ASIHTTPRequestErrorDomain Code=1 UserInfo=0x17bdb0 "A connection failure occurred"
I can't find why this happen because I launched my app once (it means the cache is downloaded), and when I go throught SSH into my iPhone's App folder, I can see all cached data.
Then why when I put my iPhone in airplane mode, I got this message ?
Here is my code (pretty simple) to make the request :
NSURL *url = [NSURL URLWithString:@"http://mywebsite.com"];
[[self request] setDelegate:nil];
[[self request] cancel];
[self setRequest:[ASIWebPageRequest requestWithURL:url]];
[[self request] setShouldAttemptPersistentConnection:NO];
[[self request] setDelegate:self];
[[self request] setDidFailSelector:@selector(webPageFetchFailed:)];
[[self request] setDidFinishSelector:@selector(webPageFetchSucceeded:)];
[[self request] setUrlReplacementMode:ASIReplaceExternalResourcesWithData];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[[self request] setDownloadCache:[ASIDownloadCache sharedCache]];
[[self request] setDownloadDestinationPath:
[[ASIDownloadCache sharedCache] pathToStoreCachedResponseDataForRequest:[self request]]];
[[self request] startAsynchronous];
I took the sample from the documentation, this is why I don't understand where is the problem.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否确认所有数据均已缓存?
服务器可以通过设置 HTTP 缓存控制标头来阻止页面缓存:“no-cache”、“no-store”、Pragma“no-store”
即使数据被缓存,也可能无法从缓存中提供服务。这是指缓存数据在后续请求时已过期。您可以通过设置缓存策略来验证后者:
ASIDontLoadCachePolicy - 如果缓存数据存在,即使它是陈旧的,也使用它。如果缓存数据不存在,则停止(不会对请求设置错误)
Did you verify that all data is cached?
The server may prevent pages from caching by setting HTTP Cache control headers: "no-cache" "no-store", Pragma "no-store"
Even if data is cached it may not be served from cache. This is when cached data has expired by the time of subsequent request. You may verify the later by setting cache policy:
ASIDontLoadCachePolicy - If cached data exists, use it even if it is stale. If cached data does not exist, stop (will not set an error on the request)