I'm using UIDocumentBrowserViewController combined with QLPreviewController to preview documents selected by users in UIDocumentBrowserViewController, which works perfectly fine. The pickedDocumentURL
variable used by QLPreviewController
is populated as follows:
func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) {
// (...)
pickedDocumentURL = documentURLs.first as NSURL?
// Present QLPreviewController instance ...
}
However, when I populate the pickedDocumentURL
variable using:
pickedDocumentURL = NSURL(string: documentURLs.first!.absoluteString)
or:
pickedDocumentURL = URL(string: documentURLs.first!.absoluteString) as NSURL?
... then the QLPreviewController
does not work (it is presented, but the preview is empty) and I get the following error on the console:
[default] QLUbiquitousItemFetcher: could not create sandbox wrapper. Error: Error Domain=NSPOSIXErrorDomain Code=1 "couldn't issue sandbox extension com.apple.quicklook.readonly for '/private/var/mobile/Containers/Shared/AppGroup/07524B34-D877-449F-A5C3-89A0431560E5/File Provider Storage/22207162/1qrbGgy6-u0f69mPqOjjpzlYiUYPR8OG_/Sample.pdf': Operation not permitted" UserInfo={NSDescription=couldn't issue sandbox extension com.apple.quicklook.readonly for '/private/var/mobile/Containers/Shared/AppGroup/07524B34-D877-449F-A5C3-89A0431560E5/File Provider Storage/22207162/1qrbGgy6-u0f69mPqOjjpzlYiUYPR8OG_/Sample.pdf': Operation not permitted} #PreviewItem
Moreover, the URL absolute strings in each of those cases are exactly the same.
Here's the code that works for me: