Description of iOS sandbox path changes

Source: Internet
Author: User

When I recently saved a file with a sandbox, I found a strange phenomenon, because of business needs, I will save the absolute path of the file for the next read.

So found a phenomenon, that is, the last time to save the absolute path, and then the second time to open the app to find the time, found that can not find ...

Like what:

The first time I saved a file, save the path as follows:

/users/macbook/library/developer/coresimulator/devices/42b54721-b3eb-448a-a450-1e11165011a0/data/containers/ data/application/5cbbf509-bd9b-4aa9-aa19-a04fc5c791e6/documents/picture/11/20160818115808

Then save the path to a place, next to the path to fetch the file, and then back to the problem I described above.

The reasons are as follows:

After iOS8, Apple adds a new feature that will regenerate the sandbox [unique encoding path] (red box) in the app every time, and keep the last sandbox file (documents, Library, TMP) moved to the newly generated file, delete the old file, that is, the files you saved are in, Only after each open, there is a new absolute path.


Therefore, in the future to access the file, you need to avoid my previous practice, do not record absolute path, then how to do?

It's really simple: make sure you use a similar Nssearchpathfordirectoriesindomains method every time to get the documents file path, because it gets to the sandbox file that you always use, the contents of the file will always exist.

As follows:

nsstring *path = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, Nsuserdomainmask, YES) firstobject];

Or

NSString *path = [nshomedirectory() stringbyappendingpathcomponent:@ "Documents" ];

This ensures that the path is not taken again, is the latest path, and avoids the error caused by the absolute path.

Finally remember: do not record the absolute path next time.

The full text ends.

Description of iOS sandbox path changes

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.