2012-12-22 5 views
8

私のアプリケーションでAFNetworkingを使用していて、キャッシュされたデータを利用できる場合はオフラインモードで動作させようとします。AFNetworking(AFHttpClient)オフラインモードがNSURLRequestReturnCacheDataDontLoadポリシーで動作しない

リクエストキャッシュポリシーをNSURLRequestReturnCacheDataDontLoadに設定した後、getPath:parameters:success:failure:オフラインでキャッシュされたデータで成功します。しかし、キャッシュにデータがあっても(コードでキャッシュを確認して確認した)、getPathは単に飛行機モードで失敗するだけです。

AFNetworking githubにスレッドがありました:https://github.com/AFNetworking/AFNetworking/issues/378しかし、問題はすべて解決されていないようです。 AFNetworkingの著者は、単にApple's documentを指し、それは言った:Appleが言ったように

NSURLRequestReturnCacheDataDontLoad Specifies that the existing cache data should be used to satisfy a request, regardless of its age or expiration date. If there is no existing data in the cache corresponding to a URL load request, no attempt is made to load the data from the originating source, and the load is considered to have failed. This constant specifies a behavior that is similar to an “offline” mode.

は、NSURLRequestReturnCacheDataDontLoadが正確にオフラインモードのために設計されています。

私はiOS6でテストを行っています。私はNSURLCacheとSDURLCacheの両方でテストしましたが、すべて同じ結果になります。

要求が失敗し、エラーメッセージ:、それはiOSの6

のバグが判明

2012-12-22 03:11:18.988 Testapp[43692:907] error: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x211b87c0 {NSErrorFailingURLStringKey=http://Testapp.com/api/v1/photo/latest/, NSErrorFailingURLKey=http://Testapp.com/api/v1/photo/latest/, NSLocalizedDescription=The Internet connection appears to be offline., NSUnderlyingError=0x211b9720 "The Internet connection appears to be offline."}

答えて

7

だこの問題のために、正確にAFNetworkingでのディスカッションスレッドがあります:https://github.com/AFNetworking/AFNetworking/issues/566

この問題についてのguykogusのヒントと実験をありがとう。私はこの問題について夜を過ごしました!

Aの周りの仕事をまとめたが、代わりに使用NSURLRequestReturnCacheDataDontLoadポリシーのキャッシュからの応答を、読まれる:

NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request]; 
if (cachedResponse != nil && 
    [[cachedResponse data] length] > 0) 
{ 
    // Get cached data 
    .... 
} 
関連する問題