在Mac OS X中启用沙箱的情况下写入文件夹 [英] Write folder in Mac OS X with sandbox active

查看:188
本文介绍了在Mac OS X中启用沙箱的情况下写入文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cocoa Desktop在Xcode中创建了一个小型应用程序,该应用程序必须在当前用户的桌面Mac OS X中创建一个文件夹

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

有人知道如何解决此问题,因为使用沙箱必须将应用程序发送到AppStore?

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

推荐答案

无论您是否正在使用沙箱,都不应仅在桌面上创建文件夹.而是使用配置为选择文件夹的NSOpenPanel并要求您的用户为您提供要使用的文件夹.这与开放和沙盒应用程序兼容.

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

这篇关于在Mac OS X中启用沙箱的情况下写入文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆