问题
I am developing a Cocoa application, and it requires 10.7+. So, I will gladly use the new shiny APIs.
What I would like to do is download some MP3s and probably some XML data from our back-end server, and store it on the user's Mac. I would much like to store it within the "application.app" directory, alongside the initial resources that are bundled with the application.
Can I do that? Store files within the application.app?
If not, where is the preferred directory to store the additional data?
NOTE: It must support apple's new sandboxing thingie.
(Is this a good idea: reference)
// save our buddy list to the user's home directory/Library/Preferences.
[prefs writeToFile:[@"~/Library/Preferences/MiniMessage Client.plist"
stringByExpandingTildeInPath] atomically: TRUE];
回答1:
Here's Apple's App Sandbox Design Guide and read the "Container Directories and File System Access". The directory "~/Library/Container/com.yourcompany.yourappname/" and it's subdirectories will be your Apps only, so seems to me that that directory would be your best place of saving the things you'll be downloading from the web.
来源:https://stackoverflow.com/questions/10169223/storing-downloaded-files-in-cocoa