本文介绍了QLPreviewView无法在沙箱中显示Quicklook预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 QLPreviewView 在应用程序中显示快速外观预览.如果没有沙箱,效果很好,但是将应用程序更改为沙箱后,预览将无法显示.

I use QLPreviewView to show the quicklook preview in the app. Without sandbox, this works well, but once change the app to sandbox, the preview can not show up.

我在控制台中发现错误:QuickLookUIHelpe(20786) deny file-read-data XXX.

I found the error in Console: QuickLookUIHelpe(20786) deny file-read-data XXX.

我使用了安全范围内的书签& com.apple.security.files.user-selected.read-write 授予访问用户主目录的权限,然后:

I have used the security-scoped bookmarks & com.apple.security.files.user-selected.read-write to grant access the user home dir, then:

[allowedURL startAccessingSecurityScopedResource];
self.myPreiviewItem.myURL = fileURL;
self.myQLPreviewView.previewItem = self.myPreiviewItem;
[self.myQLPreviewView refreshPreviewItem];
[allowedURL stopAccessingSecurityScopedResource];

使用这些,我可以删除用户主目录的文件,但是QLPreviewView无法工作.我不知道这两个场景之间有什么区别,QLPreviewView是否需要更多用于沙箱的内容?

with these, I can delete files of user home dir, but the QLPreviewView can not work.I do not know what is the difference between these 2 scenes, does QLPreviewView need more for sandbox?

如果将 com.apple.security.files.downloads.read-only 添加到授​​权中,则可以预览下载"中的文件,但不能复制用户主目录的其他文件预览.

If I add com.apple.security.files.downloads.read-only into the entitlement, the files in "Downloads" can be previewed, but other files of user home dir can not be previewed.

推荐答案

最后我找到了解决方案!

Finally I have found the solution!

refreshPreviewItem是异步调用,因此在Mac完成加载预览之前,以下api stopAccessingSecurityScopedResource立即关闭访问,结果Mac无法成功加载预览.

refreshPreviewItem is an async call, so before Mac finishes loading the preview, the following api stopAccessingSecurityScopedResource immediately shutdown the access, as a result, Mac failed to load the preview successfully.

所以解决方案是:在此处执行调用stopAccessingSecurityScopedResource,保持对allowedURL的访问权限,直到不需要QL预览功能为止,然后在此处调用stopAccessingSecurityScopedResource,例如关闭时窗口.

so the solution is: do NOT call stopAccessingSecurityScopedResource here, keep the allowedURL's access right until you do not need the QL preview function, and then call stopAccessingSecurityScopedResource there, such as when closing the window.

这篇关于QLPreviewView无法在沙箱中显示Quicklook预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-20 23:38