iOS sandbox (sandbox) mechanism and get sandbox path

Source: Internet
Author: User

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
    • Get Documents Path
    Nsarray *arrayofdocpath =Nssearchpathfordirectoriesindomains(nsdocumentdirectory,Nsuserdomainmask,YES); nsstring *docpath = [Arrayofdocpath objectatindex:0];
    • Get the Library Path
    Nsarray *arrayoflibpath =Nssearchpathfordirectoriesindomains(nslibrarydirectory,Nsuserdomainmask,YES); nsstring *libpath = [Arrayoflibpath objectatindex:0];
      • Get caches path
    Nsarray *arrayofcache =Nssearchpathfordirectoriesindomains(nscachesdirectory,Nsuserdomainmask,YES); nsstring *cachespath = [Arrayofcache objectatindex:0];
      • Get Preferences Path
    NSString *prepath = [LibPathstringbyappendingpathcomponent:@ "Preferences"];//throughLibrarypath stitching on the folder name, generally do not read, modify the file under the folder
    • Get the TMP path
    NSString *tempath =nstemporarydirectory();
    • Get the App Directory
    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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.