Uygulamamda AFNetworking kullanıyorum ve varsa önbelleğe alınmış verileri kullanarak çevrimdışı modda çalışmayı deneyin.AFNetworking (AFHttpClient) çevrimdışı modu NSURLRequestReturnCacheDataDontLoad ilkesiyle çalışmaz
İstek önbellek ilkesini NSURLRequestReturnCacheDataDontLoad olarak ayarladıktan sonra getPath: parameters: success: failure: çevrimdışıyken önbelleğe alınmış verilerle başarı elde edersiniz. Ancak, önbellekte veri olsa bile (kodun önbelleğini işaretleyerek doğruladım), getPath yalnızca uçak modunda başarısız olur.
AFNetworking'de bir iş parçacığı oluştu: https://github.com/AFNetworking/AFNetworking/issues/378 Ancak sorunun hiç ele alınmadığı görünüyordu. AFNetworking yazarı basitçe Apple's document işaret ve denildi: Elma söylediği gibi
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 tam çevrimdışı modu için tasarlanmıştır.
iOS6'da test ediyorum, hem NSURLCache hem de SDURLCache ile test ettim, hepsi aynı sonuca sahip.
istek, hata mesajı başarısız oldu:
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."}