无法确定 URL 是否由文件提供程序管理 [英] Failed to determine whether URL is managed by a file provider

查看:19
本文介绍了无法确定 URL 是否由文件提供程序管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两天我遇到了这个问题

Since two days I have this problem

我尝试了很多,

https://stackoverflow.com/a/51764198/10392572

https://stackoverflow.com/a/46457518/10392572

https://stackoverflow.com/a/51218715/10392572

如果我是对的,UIActivityViewController 需要文件的 url 数组,documentInteractionController 需要一个 url 并且都询问用户他想要做什么,但每次,如果用户使用保存到文件" 我有:

If I'm right, UIActivityViewController need an array of url(s) of the file(s) and documentInteractionController need an url and both ask user what he want do, but every time, if the user use "save to file" I have:

[default] [ERROR] 无法确定 URL/Users/lukashedinger/Library/Developer/CoreSimulator/Devices/45A185C5-6DEA-4A52-B415-939758FB7F7E/data/Containers/Data/Application/D4E32740-93A6D-BEC1-EECEB8CF732D/tmp/Vitalstoffwerte 22092018-22092018.pdf (n) 由文件提供者管理

[default] [ERROR] Failed to determine whether 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) is managed by a file provider

有人知道是否有其他方法可以询问用户,他想将文件保存在何处,或者我可以如何处理我的错误?

Anyone have idea if there is other way to ask user, where he want save a file or what I can do with my error?

简而言之,她是我的代码,也许有问题?

Her is my code in short, perhaps something is wrong?

    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)

------- 更新:为我的问题找到了一种方法,但不适用于文件 -----

------- UPDATE : Found a way for my problem, but not for file -----

我已将 pdfData 直接提供给 ViewController,尚未将其保存到文件中.

I've given the pdfData direct to ViewController, haven't saved it to file.

UIActivityViewController(activityItems: [pdfData], applicationActivities: nil)

UIActivityViewController(activityItems: [pdfData], applicationActivities: nil)

我没有使用文件,这对我来说已经足够了

I'm not using a file and that is good enough for me

-- 更新 --

我的新想法是首先尝试保存文件并尝试它的 URL,如果失败,则直接使用 pdfData,因为在某些模拟器中使用 URL 不会出错,而在其他模拟器中会出错.

My new idea is that first try to save the file and try it's URL, and if this fails, then use the pdfData directly, because in some simulator using URL gives no error and in other gives error.

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

推荐答案

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

I had the same problem on my Simulator. But when I tried it on a real device it was working as expected.

这篇关于无法确定 URL 是否由文件提供程序管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆