【发布时间】:2018-09-22 13:22:08
【问题描述】:
因为这两天我有这个问题
我尝试了很多,
https://stackoverflow.com/a/51764198/10392572
https://stackoverflow.com/a/46457518/10392572
https://stackoverflow.com/a/51218715/10392572
如果我是对的,UIActivityViewController 需要一个文件的 url 数组,而 documentInteractionController 需要一个 url 并且都询问用户他想要做什么,但是每次,如果用户使用“保存到文件” " 我有:
[默认] [错误] 无法确定 URL /Users/lukashedinger/Library/Developer/CoreSimulator/Devices/45A185C5-6DEA-4A52-B415-939758FB7F7E/data/Containers/Data/Application/D4E32740-958D-43A6 -BEC1-EECEB8CF732D/tmp/Vitalstoffwerte 22092018-22092018.pdf (n) 由文件提供者管理
任何人都知道是否有其他方法可以询问用户,他想将文件保存在哪里,或者我可以用我的错误做什么?
简而言之,她就是我的代码,也许有问题?
let dateiName = "Vitalstoffwerte " + heuteString
let path = "\(NSTemporaryDirectory())\(dateiName).pdf"
pdfData.write( toFile: path, atomically: true)
let fileUrl: URL = URL(fileURLWithPath: path)
let activityViewController = UIActivityViewController(activityItems: [fileUrl], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
------- 更新:找到了解决我的问题的方法,但不是解决文件问题-----
我已将 pdfData 直接提供给 ViewController,但尚未将其保存到文件中。
UIActivityViewController(activityItems: [pdfData], applicationActivities: nil)
我没有使用文件,这对我来说已经足够了
-- 更新--
我的新想法是,首先尝试保存文件并尝试它的 URL,如果失败,则直接使用 pdfData,因为在某些模拟器中使用 URL 不会出错,而在其他模拟器中会出错。
【问题讨论】:
-
传递给
UIActivityViewController的路径应该是一个已经存在的文件。在显示活动控制器之前,您真的有那个特定的 PDF 文件吗? -
我认为是的,因为我尝试使用其他文件。有人对我说,我不能使用网址。他说,也许我可以使用 Typ UIActivityItemProvider 的 Trapper 或带有 UIActivityItemSource Protokoll 的自己的类。
标签: swift uiactivityviewcontroller