React to Mac access rights question dialog

Mac access rights question dialog
I would like to react to the user response of the Mac dialog shown. This is displayed when I use Xojo’s SaveFileDialog. Since this dialog is Mac specific, I guess it is not taken into account by SaveFileDialog. I assume that I have to use a Mac declare instead of SaveFileDialog.
Could someone provide me a link to an appropriate example code - without using a commercial plugin?

I have never seen this message when using SaveFileDialog correctly.
Are you 100% positive you’re not using SpecialFolder.Desktop?

1 Like

This is my code:
Var file As FolderItem
Var dialog As New SaveFileDialog
dialog.SuggestedFileName = “PicDB”

#If Not (TargetLinux) then
dialog.InitialFolder = SpecialFolder.Documents
#Else //open Home directory on linux
dialog.InitialFolder = SpecialFolder.home

dialog.Title = I18n.TitleCreatePicDB
file= dialog.ShowModal

If file <> Nil Then

End If

The access rights dialog only prompts when the user navigates in SaveFileDialog to another Directory. When the user answers with No, saving the file is already done, because the access rights dialog seems to work in an own thread. I find it confusing for the customer if he answers with No, but his answer is ignored.
Is there a possibility to forbid navigating to another Directory in SaveFileDialog?

Setting InitialDirectory on macOS isn’t a thing you should do. It’s not expected behavior for users who comfortably understand macOS. The correct behavior for that dialog is to show the last directory the user navigated to, and the OS will do this for you. Secondarily, it can cause “App wants to access {folder}” warnings.

Try taking out InitialDirectory for macOS and see if that error goes away.

Er I don’t think so. This sounds horribly unfriendly to the user.

I tried removing InitialDirectory. The result is the same. In case the user navigates to a directory where access rights have to be questioned by operating system the dialog appears. In my opinion this is a correct behaviour. What is not correct is that SaveFileDialog does not handle this, allowing to save a file even if the user does not give access rights.

I have never seen navigating SaveFileDialog ask for permission. Navigating that window is a user action, requesting access is redundant approval. I would argue the behavior you’re seeing is wrong if it were an RFC.

I don’t think I can help any further. I usually see this problem when people set InitialDirectory, and have never seen it otherwise. Hopefully someone else can help :confused:

Sorry for not digging deep enough.
You were right: SaveFileDialog behaves correctly. The access right question occurs when I use the given filepath to create a SQLiteDatabase with the following code:

DB.DatabaseFile = dbFile
Catch error As IOException
ShowInStatusbar(I18n.errorCreateDB, kSeverityFatal)
End Try

Catching IOException seems not to be enough.

I believe you have to use bookmarks in this situation.

What’s the code between If file <> Nil Then and DB.DatabaseFile = dbFile ?

If the user is selecting the location of the database file, then you should use the object returned by the SaveFileDialog.

That would be too much code now. Thanks for your help :+1:. I now know I have to check the database creation parts.

So there’s several things.

  1. Your application is only allowed to access certain folders once the user has granted permission. The system uses your code signature (the Ad-Hoc one isn’t good enough) to store that setting. Using App Wrapper, and it’s scripting capability, you can properly code sign your debug builds.

1 a. To make the process smoother, you should also include a message to the user, justifiying why your application needs access to a restricted folder. This can be done on the Capabilities pane of App Wrapper.

1 b. If you intend to ship on the Mac App Store, that uses a different scrutiny system where your application will be denied access to that folder. There is an entitlement that will allow your app to access it, but these are reserved for Apple’s preferred developers. Once a user selects that folder in a selectFolderDialog, you can use Apple’s buggy Security-Scoped Bodgemarks (One of the original developers has recent stated he was surprised that the bugs in this system still have not been fixed). You still have to jump through hoops to access it, and these are incompatible with Xojo’s SQLDatabases.

I had a feature request with Apple to allow apps to have a folder within the users documents folder that we can just access when we need. Apple have rejected this feature request.

The safe way is to save or suggest a folder that your app is guaranteed to have access to, however for storing user accessible data, this now breaches App Store Rules.

  1. Xojo’s SQLDatabase library is not compatible with Apple’s Security-Scoped Bodgemarks. Apple’s own SQL library is, but that’s a buggy POS. So if you’re thinking to put your application in the Mac App Store, you’re going to have to find an alternative solution.

2 a. The best solution I found was move and link, whereby you move the selected database to a location you can access, then create a hard link back in the original location. However Apple have patched that “hole” and now this solution is no longer viable.

1 Like

Thanks for the detailed explanations!
Since I will only use the app in a private sphere, I basically store the Sqlite database in UserHome now. For naming the database I replaced the SaveFileDialog with an individual one without directory selection.