How to use NSURLCache to return cached API responses when offline (iOS App)

时光总嘲笑我的痴心妄想 提交于 2019-12-02 23:19:56
Del Brown

Did you see this post?

AFNetworking (AFHttpClient) offline mode not working with NSURLRequestReturnCacheDataDontLoad policy

Looks like it might be a bug with iOS 6. Here is what Robert Mao had to say in the post:

A summarized work around is read the response from cache, instead of use NSURLRequestReturnCacheDataDontLoad policy:

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

Unless all of your calls are 100% GET and free of side effects or time dependency then this is dangerous.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!