On an iOS system, each app has its own sandbox, and the app can only access files under its corresponding sandbox directory. Of course, in the case of user authorization, the app can also access files under other directories. For example, in the case of user authorization, the app can access albums, Contacts. In development, it often involves the IOS sandbox directory, such as reading and writing files, archiving, and so on.
A: The directory structure of the sandbox
The sandbox directory structure of the app is as follows:
There are three folders in the Sandbox directory: Documents, Library, Temp. Among them, there are two folders under the library, namely Preferences and Caches.
II: Files stored in each directory
1:documents directory: Used to store user data, all application data files should be written to that directory.
2:library directory: (1) Preferences directory: Contains the application's Preferences file (2) Caches directory: Used to store application-specific support files, saving the information needed during the application restart.
3:temp directory: For storing temporary files, save information that is not needed during the application restart.
Three: How to get the sandbox directory
Get the Sandbox directory path through the Nssearchpathfordirectoriesindomains method, the method has three parameters:
1:directory the enum value of the Nssearchpathdirectory type, the name of the directory to search for emoticons.
2:domainmask the enum value of the Nssearchpathdomainmask type, specifying the search scope. Typically, Nsuserdomainmask, which indicates that the search scope is limited to the currently applied sandbox directory.
A 3:expandtilde bool value that indicates whether to expand ~ in the returned path. If yes, expands, no indicates no expansion.
To get the code for the Sandbox directory path:
//Get Sandbox home directory pathNSString *Homedir= nshomedirectory();//Get documents directory pathNSString *Docdir= [Nssearchpathfordirectoriesindomains(nsdocumentdirectory, Nsuserdomainmask,YES)Firstobject];//Get directory path of libraryNSString *Libdir= [Nssearchpathfordirectoriesindomains(nslibrarydirectory, Nsuserdomainmask,YES)Lastobject];//Get caches directory pathNSString *Cachesdir= [Nssearchpathfordirectoriesindomains(nscachesdirectory, Nsuserdomainmask,YES)Firstobject];//Get the TMP directory pathNSString *TmpDir= nstemporarydirectory();
Example path when the third parameter is yes:
/var/Mobile/Applications/DBAC1849-cf0a-435A-98FB-a7472c73ec42/Library/Caches/letuallclassifystring.plist
example path when the third parameter is no:
~ /library/ Caches / letuallclassifystring . plist
IOS Sandbox directory Structure