Desktop Sandboxing Issue with Swift macOS

為{幸葍}努か 提交于 2019-12-12 18:26:08

问题


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.

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

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

Thanks in advance.


回答1:


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

  • Open/Save dialog for temporary access if the appropriate entitlement is set.
  • A security scoped bookmark for permanent access but also in this case the user must first choose the folder once via Open/Save dialog and the security scoped bookmark must be created programmatically.


来源:https://stackoverflow.com/questions/51310678/desktop-sandboxing-issue-with-swift-macos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!