AFNetworking (AFHttpClient) offline mode not working with NSURLRequestReturnCacheDataDontLoad policy

自作多情 提交于 2019-12-05 05:23:16

Turned out, it's a bug in iOS 6.

There is a discussion thread in AFNetworking exactly for this problem: https://github.com/AFNetworking/AFNetworking/issues/566

Thanks for guykogus' tips and experiments on this issue. I spent a night on this issue!

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