In order to save traffic, but also for a better user experience, many applications now use the local caching mechanism so I looked up the relevant data from the Internet, and found that there are generally two ways. One is to write their own cache processing, one is the use of asihttprequest in the Asidownloadcache.
Here I mainly introduce the first self-study write cache processing mode.
1. The main idea is that the first time there is a network load data to write data into the sandbox, and then log on to the network status to judge, if no network to use the sandbox data, network on the request API to obtain data.
Write Data
Nsarray *arr = Nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsalldomainsmask, YES);
Get sandbox path
Nsstring*path = [arr =objectatindex:0];
NSSTRING*PSTR = [path=stringbyappendingstring:@ "/data.txt"];
NSData *data1=nsdata DATAWITHCONTENTSOFFILE:PSTR];
Get Sandbox data
Nsarray*array=[nskeyedunarchiver Unarchiveobjectwithdata:data1];
But the way to note this is that there are more and more cached data, so the basic app has a way to delete the cache in the personal settings.
Delete Cache
Nsfilemanager * FileManager = [[Nsfilemanager alloc]init];
[FileManager Removeitematpath:path Error:nil];