我正在尝试实现查看屏幕截图。运行代码时,出现一些错误,捕获失败。
这是我的代码:
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]
日志显示客户缺少权利。但是如何获得权利? 我用关键字在日志中搜索了错误,但没有发现有用的东西。 有人遇到过类似的问题吗?
答案 0 :(得分:1)