Group Group Group Group Group Group Group Group Group

SQLite3 and Mac OS X App sandbox problem

I have implemented a Mac OS X app using the SQLite3 tutorial as a starting point and a wrapper for all the sql functionality I need. I have run into a problem using my own created database files external to the App Sandbox. The problem is that sqlite3 needs to read and write to the db file itself, yet even with “User-Selected File” capability set to read/write, the db can create the file but is not allowed to then re-use the file with the opaque db pointer (even with folder permissions set to everyone). I tried to use the AppSandboxFileAccess solution on GitHub (after porting it to Swift) but this makes no difference. I also considered doing it with a document-based app but this would not work since there is no “data” to read/write - this is done directly by the sqlite3 framework and I have no control over it. Short of writing my own database, any thoughts on what I am doing wrong (or is this even possible)?

  1. What do your entitlements look like?
  2. What path are you using for the database file?
  3. If only your app accesses the file, did you try placing it in your application support / library path?

Consider checking this Design Guide out.

Thank you for responding.
Here are my capability and entitlements settings (pictures)

The path that works is within the App Sandbox:
/Users/ddarby/Library/Containers/com.cerescape.Accountable/Data/Documents/

But the path I want to use is any arbitrary path eg
/Users/ddarby/Documents

It works just fine within the App Sandbox, so I’m not looking for a solution (ie fixed path directories) but instead want the generic solution for a user selected file location.

You have User Selected File on Read/Write, however that means you have to literally as a user, use the File Open dialog to choose the file prior to getting permission to open it. Is this something that happens during your use cases?

I use the NSSavePanel to get a file URL from the user which could be outside the App Sandbox. However, even if I choose a location programmatically (with a known URL) outside the sandbox, the sqlite3 library fails to access the file. It accesses files within the App Sandbox just fine.