first, what is a sandboxEach iOS app is limited to "sandbox" and "sandbox" is the equivalent of a folder with only the owner's visible permissions, and Apple has the following restrictions on the sandbox. 1, the application can operate in their own sandbox, but can not access any other application of sand 2, the application can not share data, the files in the sandbox can not be copied to other application folders, and can not be copied in other application folder files into the sandbox. 3. Apple prohibits any reading or writing of files outside the sandbox, and prevents the application from writing content to a folder other than the sandbox. 4. The iOS app's sandbox includes three folders:
- Documents
Apple's official recommendation is to keep the file data that is created in the program or the program viewed in the documents directory, which is backed up or restored when itunes backs up data or recovers data;
- Library
The primary store is the default settings or other status information. Consists of the following two folders:
-
- Caches
Store the cache file, the store application starts again as needed, and itunes does not back up the directory;
- Preferences
Store application Preferences file, generally do not modify the files stored here;
- Tmp
Provides a place to store temporary files. Once the iphone restarts the contents of the TMP directory, it will be emptied.
second, how to get the sandbox path1. Get the Sandbox root directory (1),NSString*nshomedirectory (void)Direct Access NSString *homepath =nshomedirectory();(2), throughNSString*nshomedirectoryforuser (NSString*username)Get NSString *username =Nsusername(); nsstring *homepath2 = nshomedirectoryforuser(userName);2. Get the sandbox other file paths documents, libraries, caches search by the following methods:Nsarray*nssearchpathfordirectoriesindomains (nssearchpathdirectorydirectory, Nssearchpathdomainmask Domainmask,BOOLExpandtilde); Nssearchpathdirectory,Enumeration values, developing subdirectories in the search sandbox nssearchpathdomainmask, enumeration value, specifying the search scope Expandtilde, whether full path is displayed
Nsarray *arrayofdocpath =Nssearchpathfordirectoriesindomains(nsdocumentdirectory,Nsuserdomainmask,YES); nsstring *docpath = [Arrayofdocpath objectatindex:0];
Nsarray *arrayoflibpath =Nssearchpathfordirectoriesindomains(nslibrarydirectory,Nsuserdomainmask,YES); nsstring *libpath = [Arrayoflibpath objectatindex:0];
Nsarray *arrayofcache =Nssearchpathfordirectoriesindomains(nscachesdirectory,Nsuserdomainmask,YES); nsstring *cachespath = [Arrayofcache objectatindex:0];
NSString *prepath = [LibPathstringbyappendingpathcomponent:@ "Preferences"];//throughLibrarypath stitching on the folder name, generally do not read, modify the file under the folder
NSString *tempath =nstemporarydirectory();
NSString *bundlepath = [[NSBundleMainbundle]Bundlepath];
- Get the resource file path in the app
NSString *imgpath = [[NSBundleMainbundle]Pathforresource:@ "01loading.png"OfType:Nil];//This method has multiple overloads
iOS sandbox (sandbox) mechanism and get sandbox path