Write folder in Mac OS X with sandbox active

2019-08-13 07:26发布

I created a small application in Xcode with Cocoa Desktop and this application has to create a folder in the current user's desktop Mac OS X

When I run the application without using the app creates a sandbox folder properly on desktop

If I use the sandbox putting right files for read / write I can not create a folder on the desktop

Does anyone know how to solve this as to send the application to the AppStore is necessary to use sandbox?

2条回答
闹够了就滚
2楼-- · 2019-08-13 07:39

For some applications it just better to use some directory as default directory (Eg. Mail and Firefox uses Downloads as default directory). I guess this is your case. But, for better user experience (and for higher chances of your App's acceptance in AppStore) follow best practices - like avoiding direct Desktop access. And, mostly you will find the answer yourself if you go through these guides:

查看更多
贼婆χ
3楼-- · 2019-08-13 07:55

You shouldn't just create a folder on the desktop, regardless of whether you are using the sandbox or not. Instead use NSOpenPanel configured to select folders and ask your user to provide you either a folder to use. That is compatible with both open and sandboxed apps.

In the sandbox world once you've asked the user for a folder you can create a security scoped bookmark and save it in your apps preferences; on subsequent runs you can use that bookmark to re-establish rights to access the folder without user intervention. E.g. a browser might ask once for access to a folder to store downloads and then save a security scoped bookmark to that folder.

HTH

查看更多
登录 后发表回答