I am developing a new feature for my app. I want cache all datas get from web service to read when offline.
Current, my app can cache data but when I killed my app It didn't work.
I saw an application https://itunes.apple.com/us/app/smartnews-trending-news-stories/id579581125?mt=8 can cache everything when killed application.
Do you have some suggest for me?
Thanks.
Asked
Active
Viewed 899 times
0

ThuongNM
- 25
- 6
-
2use nsuserdefault or save details in local database using sqllite or coredata – KDeogharkar Jan 25 '16 at 07:36
-
@KDeogharkar : nsuserdefaults for news app would be bad idea... let everything go in sqllite db... – Fahim Parkar Jan 25 '16 at 07:39
-
Possible duplicate of [storing data locally on the iphone](http://stackoverflow.com/questions/8040065/storing-data-locally-on-the-iphone) – Jaydeep Patel Jan 25 '16 at 08:04
-
@Fahim Parkar: Why nsuserdefaults is bad idea??? – ThuongNM Jan 25 '16 at 08:21
-
if your data is gonna be small, then NSUserDefaults is okay, but if you are gonna make news app, better to have sqllite DB instead of nsuserdefault for performance... – Fahim Parkar Jan 25 '16 at 09:41
-
AFNetWorking return an id response, how to save it? and how about core data? – ThuongNM Jan 26 '16 at 08:24
2 Answers
2
The best option is whenever your webservice call is done, save the json data in sqllite and then make all operations over sqllite DB (like displaying that data on UI) & not over data that you received in json...
This is what FB do (& hence when you open the app, you see old posts without any downloads)
For images use SDWebImage library

Fahim Parkar
- 30,974
- 45
- 160
- 276
-
how about NSCachedURLResponse? I used AFNetworking in my project. Do you have some solution for caching AFNetworking. – ThuongNM Jan 26 '16 at 07:42
-
@ThuongNM : I think NSCachedURLResponse will get expired after some time... I never used AFNetWorking – Fahim Parkar Jan 26 '16 at 07:55
-
AFNetWorking return an id response, how to save it? and how about core data? – ThuongNM Jan 26 '16 at 08:24
-
@ThuongNM : instead of coredata go with sql lite.. its very easy to understand... check [this link](http://www.appcoda.com/sqlite-database-ios-app-tutorial/) – Fahim Parkar Jan 26 '16 at 09:06
0
You can use coredata as it is faster to access and easy to implement and if images are there then you can use the documents directory to save it and save the path to coredata

Reshmi Majumder
- 961
- 4
- 15