user3114720
user3114720

Reputation:

Store and Retrieve JSON Data From Local Storage in IOS

We get image for JSON url,And then We saved image in NSMutableArray(imageArray). We have four different UIViewControls. Every Page uses this imageArray. We are not interested to call web service every page. We need imageArray Stored to Local JSON file and then we Retrieve Data form JSON.

So Please give me any idea.Thanks in Advanced.

Upvotes: 0

Views: 1099

Answers (1)

Mohd Iftekhar Qurashi
Mohd Iftekhar Qurashi

Reputation: 2405

Best solution to cache server response is to download the images using NSURLRequest/NSURLConnection, and use proper NSURLRequestCachePolicy to cache response.

To sort out your problem you can use NSURLRequestReturnCacheDataElseLoad cache policy. It will load data from server if there is no cache data locally and if found any local data then returns it without hitting server again.

For more on NSURLRequestCachePolicy and cache server response, you can read here:

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/#//apple_ref/c/tdef/NSURLRequestCachePolicy

http://www.hpique.com/2014/03/how-to-cache-server-responses-in-ios-apps/

http://codewithchris.com/preventing-nsurlconnection-cache-issues/

http://nshipster.com/nsurlcache/

Upvotes: 1

Related Questions