代码之家  ›  专栏  ›  技术社区  ›  Andrew Bennet

无法通过“在<我的应用>共享页中打开”从iOS文件应用打开文件:提供的文件URL中不存在任何文件

  •  0
  • Andrew Bennet  · 技术社区  · 7 年前

    我的iOS应用程序可以打开CSV文件,以便导入其数据。我可以通过 UIDocumentPickerViewController

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        print("Exists: \(FileManager.default.fileExists(atPath: url.path)) (\(url.path))")
        return true
    }
    

    当我从该应用程序中的文件打开一个文件时,会产生一个日志行,如:

    存在:false( /private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Reading List - Andrew’s iPhone - 2018-10-18 11-19.csv )

    可以

    存在:正确( /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/Inbox Mobile Documents/com~apple~CloudDocs ).这是什么原因造成的?我如何支持在我的应用程序中打开文件应用程序中的文件?

    我的应用程序支持的文档类型如下:

    Xcode document types

    2 回复  |  直到 7 年前
        1
  •  14
  •   Andrew Bennet    7 年前

    我通过调整应用程序Info.plist中的一些设置修复了这个问题。

    我换了 UISupportsDocumentBrowser 到 false LSSupportsOpeningDocumentsInPlace ,也设置为 错误的

    在我收到App Store Connect的一封电子邮件后,我认为这些设置(由我)设置不正确:

    https://developer.apple.com/document-based-apps/ 了解更多信息。

        2
  •  2
  •   crom87    6 年前

    LSSupportsOpeningDocumentsInPlace 标记为false可防止在文件应用程序中选择文件时自动打开应用程序。如果文件在适当位置打开,则需要首先请求/解锁访问:

     func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {     
       let opensInPlace = options[.openInPlace] != nil
       opensInPlace ? url.startAccessingSecurityScopedResource() : nil
       let fileExists = FileManager.default.fileExists(atPath: url.path)  
       opensInPlace ? url.stopAccessingSecurityScopedResource() : nil
     }
    
        3
  •  -1
  •   pkamb santoshIOS    7 年前

    我认为您不能在不同的应用程序(不在同一应用程序组中)之间共享文件:

    Sharing data between apps on iOS