简体   繁体   中英

What is the default folder to save files within an app in iOS 8

I have an app that saves files in iOS 7 without a problem and I can find them on iPad. The path is: /var/mobile/Applications/"UDID"/Documents The same app in iOS 8 and I cannot save the files and/or find them if they are saved somewhere. It tries to save it to /private/var/Containers/Bundles/Application/"UDID"/Documents but then it tries to load the saved file from /private/var/Containers/Bundles/Application/"UDID" and I am unable to change directory to /private/var/Containers/Bundles/Application/"UDID"/Documents to find the file. Any insight?

You should read TN2406: Changes to App Containers in iOS 8 , which tells us the following (emphasis added):

iOS 8 changes the locations of the standard directories used for storing user and app data (eg Documents, Library). While the locations of these directories have always been an implementation detail, some applications improperly assume that the Documents and Library directories reside in the same directory as the application's bundle. iOS 8 splits the data of an application from the application bundle. Code which attempts to derive the path to the Documents or Library directories will return an invalid path on iOS 8. Attempting to access this path will fail, and may terminate your app.

It also explains how to use NSFileManager to get the location of the Documents directory, essentially this:

NSURL *documentsDirectoryURL = [[[NSFileManager defaultManager]
                                 URLsForDirectory:NSDocumentDirectory
                                 inDomains:NSUserDomainMask]
                                lastObject];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM