我的iOS应用可以打开CSV文件,以便导入其数据。我可以通过毫无问题地从应用程序内打开文件UIDocumentPickerViewController,选择“文件”应用程序中显示的文件。但是,当先在“文件”应用程序中查看文件,然后从那里打开我的应用程序时(通过“打开方式”共享表),我的应用程序无法在传递给我的应用程序的URL上看到该文件。该文件似乎不存在。
我在我的AppDelegate中添加了以下调试代码:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
print("Exists: \(FileManager.default.fileExists(atPath: url.path)) (\(url.path))")
return true
}
Run Code Online (Sandbox Code Playgroud)
当我从此应用程序中的“文件”中打开文件时,它会导致出现如下日志行:
存在:假(
/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Reading List - Andrew’s iPhone - 2018-10-18 11-19.csv)
从其他应用程序(例如Dropbox或电子邮件)打开文件时,可以处理该文件,并记录以下内容:
存在:true(
/private/var/mobile/Containers/Data/Application/F9110F90-7A91-4AB6-A92E-0ED933184EA4/Documents/Inbox/Reading List - Andrew’s iPhone - 2018-01-27 08-03.csv)
注意不同的路径(Documents/Inboxvs Mobile Documents/com~apple~CloudDocs)。是什么原因造成的?如何在我的应用程序中支持通过“文件”应用程序打开文件?
我的应用程序支持的文档类型如下: