ASIHTTPRequest 離線模式連接失敗 (ASIHTTPRequest offline mode connection failure)


問題描述

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)

(by TroXdmitri)

參考文件

  1. ASIHTTPRequest offline mode connection failure (CC BY-SA 3.0/4.0)

#asihttprequest #caching #iphone #uiwebview #offline






相關問題

遠程服務器上的請求總是失敗 (Request always fail on distant server)

ASIHTTPRequest 緩存我的數據。我不想要任何類型的緩存 (ASIHTTPRequest caches my data. I don't want any kind of cache)

在調用之前釋放了 didFinishSelector ASIHTTPRequest 的自定義委託類 (Custom delegate class for didFinishSelector ASIHTTPRequest being deallocated before called)

Android:在後台上傳/下載文件數量的最佳方式 (Android: best way to upload/download number of files in background)

Ghi giá trị bài đăng trong ASIFormDataRequest (Log Post Value in ASIFormDataRequest)

ASIHTTPRequest - 下載問題 (ASIHTTPRequest - download problem)

ASIHTTPRequest 離線模式連接失敗 (ASIHTTPRequest offline mode connection failure)

ASIHttpRequest 請求:didReceiveBytes:未按預期工作 (ASIHttpRequest request:didReceiveBytes: not working as expected)

如何讓 Ruby on Rails 與 ASIHTTPRequest 一起使用? (How do I get Ruby on Rails to work with ASIHTTPRequest?)

可以指定一個 NSObject 作為多個 ASIHTTPRequests 的代表嗎? (OK to assign one NSObject as the delegate of multiple ASIHTTPRequests?)

需要幫助將 NSXMLParser 與 ASIHTTPRequest 一起使用 (need help using NSXMLParser with ASIHTTPRequest)

處理 ASIHTTPRequest 多個請求 (Handling ASIHTTPRequest Multiple Requests)







留言討論