Swift macOS的桌面沙箱问题 [英] Desktop Sandboxing Issue with Swift macOS

查看:110
本文介绍了Swift macOS的桌面沙箱问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在尝试编写Mac应用程序,但遇到了问题.这不是太重要,但是有一个解决方案会很棒.

I've been trying to write a Mac app lately, and have run into an issue. This is not overly major but it would be great to have a solution.

我必须在运行时加载由用户指定的图像(因此,不能,我不能按照很多的替代建议将图像嵌入捆绑包中),然后使用NSAttributedText将其嵌入到NSTextView中.图像可以从图片"目录(/Users/USERNAME/Pictures/IMAGE)等加载,但不能从桌面加载.我已经检查了Xcode中的功能"选项卡,并为所有可用选项启用了读/写":图片

I have to load an image at runtime, specified by the user (so no, I cannot embed the image into the bundle as many alternatives suggest), and embed it into an NSTextView using NSAttributedText. The image loads fine from the Pictures directory (/Users/USERNAME/Pictures/IMAGE) etc, but not from the Desktop. I have checked the Capabilities tab in Xcode, and Read/Write is enabled for all of the available options:image

使用FileManager,我确定该文件确实存在,但不可读.我可以在权利"文件中手动进行设置吗?

Using FileManager, I have determined that the file definitely exists, but is not readable. Can I set this manually in the Entitlements file?

谢谢.

推荐答案

不,您不能.如果将应用程序沙盒化,则无法直接使用标准桌面.具有相应权利的仅标准DownloadsPicturesMusicMovies文件夹可以访问.

No, you can't. The standard desktop is not accessible out of the box if the app is sandboxed. Only the standard Downloads, Pictures, Music and Movies folder are accessible with the corresponding entitlement.

有两个选项可访问其他文件夹,但在所有情况下,用户必须选择一次

There are two options to access the other folders but in all cases the user must choose them once

  • 如果设置了适当的权利,则打开/保存对话框以进行临时访问.
  • 用于永久访问的安全范围书签,但在这种情况下,用户必须首先通过打开/保存"对话框选择一次文件夹,并且必须以编程方式创建安全范围书签.

这篇关于Swift macOS的桌面沙箱问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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