【问题标题】:Failed to determine whether URL is managed by a file provider无法确定 URL 是否由文件提供程序管理
【发布时间】: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 不会出错,而在其他模拟器中会出错。

更多:https://stackoverflow.com/a/52499637/10392572

【问题讨论】:

  • 传递给UIActivityViewController 的路径应该是一个已经存在的文件。在显示活动控制器之前,您真的有那个特定的 PDF 文件吗?
  • 我认为是的,因为我尝试使用其他文件。有人对我说,我不能使用网址。他说,也许我可以使用 Typ UIActivityItemProvider 的 Trapper 或带有 UIActivityItemSource Protokoll 的自己的类。

标签: swift uiactivityviewcontroller


【解决方案1】:

我在模拟器上遇到了同样的问题。但是当我在真实设备上试用它时,它按预期工作。

【讨论】:

    猜你喜欢
    • 2018-11-05
    • 2013-08-24
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多