iOS 11上的UIDocument创建:不允许读者访问该URL [英] UIDocument Creation on iOS 11: reader is not permitted to access the URL
问题描述
自iOS 11以来,我每次使用 UIDocument
API时遇到以下错误每次创建新文档:
Since iOS 11 I have encountered the following error every time I am creating a new document using UIDocument
API:
[错误]无法获取项目 / var / mobile / Containers / Data / Application / XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX /的属性值Documents / myDoc-XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX.myFile(n)。
错误:错误域= NSFileProviderInternalErrorDomain Code = 1
不允许读者访问该URL。
UserInfo = {NSLocalizedDescription =不允许读者访问该URL。}
Error: Error Domain=NSFileProviderInternalErrorDomain Code=1
"The reader is not permitted to access the URL."
UserInfo={NSLocalizedDescription=The reader is not permitted to access the URL.}
与类似问题( 1 不同, 2 , 3 )在SO上,我没有使用 UIDocumentBrowserViewController
。我只是创建一个UIDocument并自己调用 save()
到 Documents
目录。我找到的最接近的问题使用 UIManagedDocument
。但是,就我而言,尽管出现错误消息,仍然会成功创建并写入文件。
Unlike similar questions (1, 2, 3) on SO on this, I am not using UIDocumentBrowserViewController
. I am simply creating a UIDocument and call save()
to the Documents
directory myself. The closest question I found uses UIManagedDocument
. However, in my case, the file is still created and written successfully despite the error message.
以下是我的保存例程的要点:
Here's the gist of my save routine:
@IBAction func createDoc(_ sender: Any) {
let uuid = UUID().uuidString
let doc = Document(baseName: "myDoc-\(uuid)")
doc.save(to: doc.fileURL, for: .forCreating) { (completed) in
if (completed) {
doc.close(completionHandler: nil)
self.verifyNumberOfFiles()
}
}
}
为了简化这个问题,我的 UIDocument
子类也几乎为空:
My UIDocument
subclass is also almost blank for simplicity of this question:
class Document: UIDocument {
let fileExtension = "myFile"
override init(fileURL url: URL) {
super.init(fileURL: url)
}
/// Convenience method for `init(fileURL:)`
convenience init(baseName: String) {
self.init(fileURL: documentsDirectory.appendingPathComponent(baseName).appendingPathExtension(Document.fileExtension))
}
override func contents(forType typeName: String) throws -> Any {
return NSData()
}
override func load(fromContents contents: Any, ofType typeName: String?) throws {
}
}
我总是写信给文件
文件夹,我的查找例程可以验证我的文件是否已成功创建:
I'm always writing to Documents
folder, and my lookup routine can verify that my files are successfully created:
public var documentsDirectory: URL {
return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!
}
func loadFileURLs(from dirURL: URL) -> [URL]? {
return try? FileManager().contentsOfDirectory(at: dirURL, includingPropertiesForKeys: nil)
}
我是什么到目前为止已经发现:
What I have discovered so far:
- 即使我已经设置了UTI,也会出现错误。请参阅此和这个。
- 当我向我发送myFile时,我可以验证我的UTI是否有效设备通过AirDrop并正确触发我的应用程序打开。
- 该错误仅出现在iOS 11上。相同的代码不会在iOS 10上重现错误,例如上面的问题。
- 我尝试添加
UISupportsDocumentBrowser
键,虽然我没有使用浏览器,但它没有解散错误。
- The error appears even when I set up my UTI already. See this and this.
- I can verify that my UTI works when I send a "myFile" to my device over AirDrop and it correctly triggers my app to open.
- The error appears on iOS 11 only. The same code doesn't reproduce the error on iOS 10, like in the question above.
- I tried adding
UISupportsDocumentBrowser
key although I'm not using the browser but it's not dissolve the error.
发生了什么事?这只是iOS 11上的噪音错误消息吗?
What is happening? Is this just a "noise" error message on iOS 11?
这篇关于iOS 11上的UIDocument创建:不允许读者访问该URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!