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