沙盒扩展程序创建失败:客户端缺少权利?路径:

时间:2018-11-28 23:31:56

标签: swift xcode macos

我正在尝试实现查看屏幕截图。运行代码时,出现一些错误,捕获失败。

这是我的代码:

func saveSelfAsImage() {
    self.lockFocus()
    let image = NSImage(data: self.dataWithPDF(inside: self.bounds))
    self.unlockFocus()
    let imageData = image!.tiffRepresentation

    let fileManager = FileManager.default
    let path = "/Users/wudi/Documents/image.png"
    fileManager.createFile(atPath: path, contents: imageData, attributes: nil)

    let fileURL = URL(fileURLWithPath: path)
    NSWorkspace.shared.activateFileViewerSelecting([fileURL])
}

这是错误日志:

2018-11-29 06:44:10.645177+0800 Chapter3[2375:192235] [sandbox] Sandbox extension creation failed: client lacks entitlements? for path: [/Users/wudi/Documents/image.png] [/Users/wudi/Documents/image.png]
2018-11-29 06:44:10.645227+0800 Chapter3[2375:192235] [general] Sandbox extension data required immediately for flavor public.file-url, but failed to obtain.
2018-11-29 06:44:10.709833+0800 Chapter3[2375:192235] [sandbox] Sandbox extension creation failed: client lacks entitlements? for path: [/Users/wudi/Documents/image.png] [/Users/wudi/Documents/image.png]

日志显示客户缺少权利。但是如何获得权利? 我用关键字在日志中搜索了错误,但没有发现有用的东西。 有人遇到过类似的问题吗?

1 个答案:

答案 0 :(得分:1)

问题已解决。 感谢EI Tomato和Willeke的帮助。

关闭应用程序沙箱或增加文件访问权限可以解决此问题。

App Sandbox configuration