对Mac OS应用程序中用户选择的文件夹的读写权限? [英] Read and write permission for user selected folder in Mac OS app?

查看:877
本文介绍了对Mac OS应用程序中用户选择的文件夹的读写权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发MAC OS应用程序,该应用程序具有代表您创建文件的功能.首先,用户选择用于存储文件的文件夹(在应用程序启动时一次),然后用户可以使用Apple脚本在所选文件夹(在应用程序启动时选择的文件夹)中选择要创建的文件的类型和名称.当我在权利文件中添加temporary-exception以下时,我可以创建文件,但它无法应用到Apple审核小组,但可以在沙箱中工作.

I am developing MAC OS app which have functionality to create file on the behalf of your. First user select folder for storing file (One time at start of app) and then user can select type and name of the file user want to create on selected folder (Folder selected on start of the app) using apple script. I am able to create file when i add below temporary-exception in entitlement file but its not able to app apple review team but works in sandboxing.

指南2.4.5(i)-效果 我们已确定为此应用程序请求的一个或多个临时权利例外是不合适的,并且不会被授予:

Guideline 2.4.5(i) - Performance We've determined that one or more temporary entitlement exceptions requested for this app are not appropriate and will not be granted:

com.apple.security.temporary-exception.files.home-relative-path.read-write
/FolderName/

我发现了:

启用应用沙箱-允许应用写入可执行文件.

Enabling App Sandbox - Allows apps to write executable files.

还有

启用用户选择的文件访问-Xcode在目标编辑器的摘要"选项卡中提供了一个弹出菜单,并提供了对文件和文件夹进行只读或读/写访问的选项用户明确选择的内容.启用用户选择的文件访问权限时,您可以通过编程方式访问用户使用NSOpenPanel对象打开的文件和文件夹,以及使用NSSavePanel对象存储用户保存的文件.

Enabling User-Selected File Access - Xcode provides a pop-up menu, in the Summary tab of the target editor, with choices to enable read-only or read/write access to files and folders that the user explicitly selects. When you enable user-selected file access, you gain programmatic access to files and folders that the user opens using an NSOpenPanel object, and files the user saves using an NSSavePanel object.

使用以下代码创建文件:

Using below code for creating file :

let str = "Super long string here"
let filename = getDocumentsDirectory().appendingPathComponent("/xyz/output.txt")

do {
    try str.write(to: filename, atomically: true, encoding: String.Encoding.utf8)
} catch {
    // failed to write file – bad permissions, bad filename, missing permissions, or more likely it can't be converted to the encoding
}

还尝试在授权文件中为NSOpenPanel对象添加com.apple.security.files.user-selected.read-write:

Also tried adding com.apple.security.files.user-selected.read-write in entitlement file for an NSOpenPanel object :

<key>com.apple.security.files.user-selected.read-write</key>
<true/>

有什么方法可以让合格的Apple审核小组批准对用户选择的文件夹具有读写权限的Mac App?

Is there any way to get pass apple review team to approve Mac App with read and write permission to user selected folder ?

推荐答案

在授权文件中添加user-selectedbookmarks.app权限:

Add user-selected and bookmarks.app permissions in entitlement file :

<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.files.bookmarks.app-scope</key>
<true/>

然后使用NSOpenPanel打开文件夹选择,以便用户可以选择要授予您访问权限的文件夹. NSOpenPanel必须作为书签存储并保存到磁盘.然后,您的应用程序将具有与用户选择文件夹时相同的访问级别.

Then open folder selection using NSOpenPanel so the user can select which folders to give you access to. The NSOpenPanel must be stored as a bookmark and saved to disk. Then your app will have the same level of access as it did when the user selected the folder.

这篇关于对Mac OS应用程序中用户选择的文件夹的读写权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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