0

How can I tell which paths have been granted access by the user? I know that with NSOpenPanel, the sandbox is automatically expanded to allow access to the directory the user chooses. Is this information stored anywhere so I can know whether I need to throw up an NSOpenPanel or not?

Or do I need to track it locally in NSUserDefaults or something?

Lizza
  • 2,769
  • 5
  • 39
  • 72
  • Memoization of sandboxed resources coming from PowerBox is tracked by NSDocumentController only, IIRC. You could persist the paths from the open panel, but what would be the point of that? The app sandbox or user may just as well choose to shut you out of that file and you'd be back to square one. Open panels are meant for one-time interactions with the filesystem. – CodaFi Sep 30 '13 at 05:22

2 Answers2

2

You are responsible to store already-granted paths using the Secure Bookmarks, read NSURL documentation.

If you need to access to a path check if you have it on secured bookmarks (stored for example inside NSUserDefaults) if you have reuse it otherwise show the open panel

dafi
  • 3,492
  • 2
  • 28
  • 51
1

If you need to know whether the current execution of your app can access a particular path you can call access - see the unix man pages section 2. You can test for read, write and execute access, and the result reflects the current sandbox.

If you want to preserve access between executions of your app then you need to create security scoped bookmarks and stored them in user defaults or some other file.

CRD
  • 52,522
  • 5
  • 70
  • 86