Load offline cached JSON using AFNetworking

三世轮回 提交于 2019-12-01 14:21:41

Man, i don't know swift so well but as long as i know you will have to do is:

first of all, capture the returned data from your get and save then into NSCachedURLResponse. in objective-c will be something like that:

NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:operation.response data:operation.responseData];
    [[NSURLCache sharedURLCache] storeCachedResponse:cachedResponse forRequest:urlRequest];

After that, if your requisition throws error, you will recuperate you previous data saved for that URL.

NSData *data = [[[NSURLCache sharedURLCache] cachedResponseForRequest:urlRequest] data];

I hope that helps you.

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