I have a long-standing app that on Mac that runs in a sandboxed environment. It has a single SQLite database stored in the sandboxed Application Support folder.
In my latest version I wish to implement some features involving file writing that require the app to be non-sandboxed. Longstanding users will want to update the app, but continue using their data from before.
The problem is I can’t get the new non-sandboxed app to access the existing sandboxed database.
I have learnt that if the user navigates to the sandboxed file using an OpenFileDialog, the app can then have access to the database and copy it to a non-sandboxed folder, because the user has “given permission” to access the file.
However, the sandboxed file is 8 folders deep, and is difficult to find for users. So I tried pre-filling the openFileDialog with an .initialFolder set to the sandboxed folder. No luck: Apple ignores the suggested folder because its in a sandboxed location.
Does anyone have any suggestions of how my non-sandboxed app can access a sandboxed database made by a previous version of the same app? My aim is to try to make the update as seamless as possible for my users.
Couldn’t you request access to the top-level directory via an OpenFileDialog, and then—once the app user has granted access to that folder—navigate to the desired subfolder yourself?
Thanks Sascha. I’m not 100% sure, but I think the user has to actually interact with a file in the sandboxed folders, eg open or copy. They can’t just navigate there. Which makes it cumbersome for my non-tech minded users.
I’ve managed to write a shell command that can access the sandboxed folders, and then the user simply drags the database file into a box in the app, which then copies it to a non-sandboxed folder.
I’ve seen several apps which behave that way: they ask the user to select the root folder (using a select folder dialog) to gain access to it (this behaviour is explicitly mentioned in the dialog’s prompt) and, starting from that, the app can handle the folder’s content.
IMO, you should give it a try.