1

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];
Mazyod
  • 22,319
  • 10
  • 92
  • 157
  • If I'm not wrong, I think Sandbox mode does not allow you to download files for any extension use. – TheAmateurProgrammer Apr 16 '12 at 05:58
  • You are partially right. But, by adding the appropriate entitlements, you can retrieve data from the internet. (Also, if all apps are gonna be restricted from doing that, might as well burn the appStore down.) – Mazyod Apr 16 '12 at 06:21
  • Why not use the Application Support directory? – Costique Apr 16 '12 at 06:28
  • What's that? I am interested to know more – Mazyod Apr 16 '12 at 06:57
  • 1
    You should never assume that you can store files in your application bundle. If the app is still on its disk image, you can't. If the user installed it from the MAS and hasn't moved it, you can't. If you're running under a sandbox, you can't. – Peter Hosey Apr 16 '12 at 19:49
  • 1
    And in the last case, you also can't make up random pathnames (as in your code snippet) and use those; you can only use paths/URLs that you have gotten from Cocoa, or reconstituted from a security-scoped URL bookmark. https://developer.apple.com/library/mac/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW16 – Peter Hosey Apr 16 '12 at 19:51
  • 1
    Finally, in answer to that last question, see the documentation: https://developer.apple.com/library/mac/documentation/General/Conceptual/MOSXAppProgrammingGuide/AppRuntime/AppRuntime.html#//apple_ref/doc/uid/TP40010543-CH2-SW9 https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/MacOSXDirectories/MacOSXDirectories.html#//apple_ref/doc/uid/TP40010672-CH10-SW1 – Peter Hosey Apr 16 '12 at 19:55
  • +1 - Great information, thanks! – Mazyod Apr 17 '12 at 06:31

1 Answers1

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.

TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71
  • I went over it before posting this question, but I seemed to have missed the part about container directories.. Still, I would like to make this plan B. Plan A is to store it within the application.app (making it super portable). – Mazyod Apr 16 '12 at 07:00
  • TBH, after reading the details, I shall grant this answer as Plan S, which supersedes plan A. This is how apps should store their data properly! – Mazyod Apr 16 '12 at 07:05
  • 2019. Link is dead. – Pedro Paulo Amorim Apr 29 '19 at 21:04
  • I think new link is: https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AboutAppSandbox/AboutAppSandbox.html – Wizard of Kneup Oct 21 '19 at 18:25