UIDocument Creation on iOS 11: reader is not permitted to access the URL

☆樱花仙子☆ 提交于 2019-12-03 05:55:19
Adrian Schönig

A workaround for this is to create the file by saving its data to the disk, and then open it as you would with an existing file.

Your createDoc(_:) method would then like this:

@IBAction func createDoc(_ sender: Any) {
  let uuid = UUID().uuidString
  let baseName = "myDoc-\(uuid)"
  let url = documentsDirectory
      .appendingPathComponent(baseName)
      .appendingPathExtension(Document.fileExtension)

  do {
    let emptyFileData = Data()
    try emptyFileData.write(to: url)
    let document = Document(fileURL: url)
    document.open() { completed in
      guard completed else { 
        // handle error
        return 
      }
      doc.close(completionHandler: nil)
      self.verifyNumberOfFiles() 
    }
  } catch {
    // handle error
  }
}

In Xcode 9.3 it is possible to specify a new item in info.plist:

Supports Document Browser (YES)

This enables access to the application's documents directory (for example, /var/mobile/Containers/Data/Application/3C21358B-9E7F-4AA8-85A6-A8B901E028F5/Documents on a device). Apple Developer doc here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!