問題描述
ASIHTTPRequest 離線模式連接失敗 (ASIHTTPRequest offline mode connection failure)
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.
參考解法
方法 1:
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:
[request setCachePolicy:ASIDontLoadCachePolicy];
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)