Reputation: 131
I'm writing an app which tracks disk usage. For that I let the user select drives (represented as URLs starting with /volume). I save the info using core data. Now I'd like to implement sandboxing and I'm not exactly sure how I'd proceed. There's no out-of-the-box entitlement that gives me access to this path. From what I understand, I'd need to...
Does this make sense? Am I missing something here? Any tips/hints you can provide?
Upvotes: 3
Views: 660
Reputation: 53000
Your outline is correct.
To have the user select a drive you can create an NSOpenPanel which starts at /Volumes. You can use a delegate to only allow selection of items within that directory, so even if the user navigates away they won't be able to select anything else. Customise the various messages in the dialog so it becomes a "Select Volume" dialog.
Alternatively you could put up an NSOpenPanel for /Volumes itself - have your user grant you access to that directory. If you do that once and then save a bookmark your user shouldn't be hit by a lot of annoying open dialogs. Once you've got access to /Volumes your app can allow selection of a subset of volumes if it needs to.
Caveat: while gaining access to the whole directory is possible, if you intend to put your app in the App Store you might find that Apple sees you as asking for too much from your users. You might want to start with read-only access to the directory and if they kick that back fall back to selecting individual disks - just be prepared.
You can also store the bookmarks in a plist (within your container) or user defaults, you'll need to decide if those suit better than Core Data.
HTH
Upvotes: 2