My AppStore cocoa app includes a swift-based command-line utility which is sandboxed (appstore requirement). Now, I had (wrongly) assumed that any arguments given to `Swift.CommandLine.arguments' would be covered using the entitlement: com.apple.security.files.user-selected.read-write and appropriately be handled by the sandbox. After all, the user explicitely specifies the file-URL argument of the command-line utility and initiates the file-access.
Powerbox is using Cocoa invoked via NSOpenPanel and NSSavePanel, but what is the Foundation (command-line) equivalent?
Is there API to read file-URL's from the `Swift.CommandLine.arguments' ?
The reasons I ask is because I resorted to using the entitlement 'com.apple.security.temporary-exception.files.home-relative-path.read-only' (as advised in the Apple docs) but got rejected in review. So, that implies there must be an official way of accessing the user-files from a command-line utility (or is Apple saying that users are not allowed to access there own files using command-line utilties?).
Am I missing something? If not, I will file a bug-report. Users should be able to specify file-URL's on the command-line that work directly with Powerbox.
You can't have a normal command-line app in the Mac App Store. You can only have sandboxed apps. You have to follow the rules of the sandbox. That's just the way it is.
There is a great deal of harm that could be done by reading files. You have to think like Apple. You have a billion users, each with at least $10,000 in credit. That is a lot to steal. You've got about at least a million fraudulent developers hammering at it 24x7 trying to do just that. They would love to be able to silently read user documents and upload them.
Apple doesn't do all that much reviewing and checking. They have some automated checks to look for the relatively honest developer who are merely trying to sell game tokens and avoid Apple's 30% cut. A human reviewer might launch the app and run it for 30 seconds or so just to make sure it runs on the latest OS. They are now also looking for some kind of substantial difference between the app under review and the developer's other 47, virtually identical apps. But that's pretty much it. It is easy to find apps that blatanly ignore every guideline in the book - all the way up to issuing sudo commands. That kind of stuff will make it past reviewers. But using a temporary entitlement will not. That is something they can check with automated tools.
If you use application groups, you can define a shared directory. See developer.apple.com/documentation/foundation/nsfilemanager/1412643-containerurlforsecurityapplicati
I'm don't recommend this method. I'm just pointing it out. Security scoped bookmarks are the way to go.
I suggest you also review why you even have this tool and what you are doing with it. It really isn't worth your time just to give users a command-line option. You are talking about maybe one user out of 1,000, if that. A tool outside of the Mac App Store will solve that problem, but introduce new ones. If this is a tool for your UI to use, then just use security-scoped bookmarks or maybe even do the helper as a true XPC. You can also do something really crude, but effective, like asking the user to open the root of the disk and saving that as a security-scoped bookmark. Presto! Problem solved. I think there is a risk that Apple will disallow that practice at some point, but what do I know about Apple? Anything command-line is going to be for power users, so just don't make the root access a requirement. Tuck it away under "advanced" or something. It is allowed, but frowned upon.