gpt4 book ai didi

ios - 在 iOS 11.2 上预览 PDF 文件

转载 作者:行者123 更新时间:2023-11-30 11:42:05 25 4
gpt4 key购买 nike

我遇到了这个错误,它阻止我的应用程序使用 UIDocumentInteractionControllerQLPreviewController 显示 PDF:https://forums.developer.apple.com/thread/91835

根据建议,解决方案是将文件复制到documents或tmp文件夹中,然后从那里加载文件。

但是,这对我不起作用。从 .documentDirectoryNSTemporaryDirectory() 加载文件会产生相同的错误,但现在不仅在设备上,而且在模拟器中也是如此。

编辑:以下代码为我解决了这个问题:

func copyFiles(fileName: String) -> URL {
let filemgr = FileManager.default
filemgr.delegate = self

let tempDocsFolder = URL.init(fileURLWithPath: NSTemporaryDirectory()).path

// my fileName is in format "file.pdf"
let fileSplit = fileName.components(separatedBy: ".")
let filePath = Bundle.main.path(forResource: fileSplit[0], ofType: fileSplit[1])
let destPath = "\(tempDocsFolder)/\(fileName)"

do {
try? filemgr.copyItem(atPath: filePath!, toPath: destPath)
}

return URL.init(fileURLWithPath: destPath)
}

然后返回的 URL 将被提供给 UIDocumentInteractionController。之前它对我不起作用的原因是因为我尝试将文件复制到 /tmp/documents/,但文件必须复制到 tmp 文件夹的根目录: /tmp/(我不知道为什么)。

最佳答案

检查资源(文件名)是否区分大小写。

添加代码的任何屏幕截图。

关于ios - 在 iOS 11.2 上预览 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49212449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com