I am trying to implement view screen capture. When I run my code, I got some error and the capturing failed.
Here is my code:
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])
}
Here is the error log:
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]
The log says the client lacks entitlements. But how to get the entitlements? I google the error with key word in log, but did not find anything useful. Has anyone faced a similar problem?
The problem is solved. Thanks for help from EI Tomato and Willeke.
Turning off the App Sandbox or increasing file access permissions can fix the problem.