swiftmacosappstore-sandboxnsopenpanel

Is there an NSOpenPanel alternative or can the panel be styled differently in SwiftUI?


I have asked a similar question here and at even at the Apple Developer's Forum. It seems like either I have the questions wrong or no one can / want's to comment on this subject.

The problem

I want to grant access to a folder outside the sandbox of my application. I know I can do this with an NSOpenPanel dialog - a modal popping up, where the folder is pre-selected, thus an empty view and the user is supposed to press an OK button.

The question

Since I find this "empty folder view with a random OK button" not really user friendly, I was wondering if there is a possibility to either

so that I simply have a modal popping up which alerts the user that the app needs access to a folder (which will be printed out in the alert window), with an OK and a Cancel button. I don't want to show locations on the system, an empty box of a folder and all the other stuff which is presented.

To clarify, this is what I have:

enter image description here

and this is what I want (or something similar):

enter image description here

I would really appreciate if someone could tell me if this is possible or not. At least point me to some reference (I could not find anything so far).

Thanks!


Solution

  • No. Not possible.

    NSOpenPanel & NSSavePanel have a special relationship for sandboxed apps. They are sort of an app called PowerBox within your app that allow the user to pick a file or folder and return a security scoped URL to your code.

    They are described in the documentation here

    As such if you can’t do it using the NSSavePanel/NSOpenPanel API then it can’t be done.