iOS13模拟器上的UIDocumentBrowserViewController错误"Cannot create urlWrapper for url"



我在iOS 13上测试时遇到了一个非常奇怪的UIDocumentBrowserViewController问题。importHandler(newDocumentURL, .move)似乎无缘无故崩溃:

[DocumentManager] Cannot create urlWrapper for url file:///.../tmp/23720D22-BC1D-4E7B-A7AE-A1C8B0293F9E.txt. 
error Error Domain=NSPOSIXErrorDomain Code=22 "couldn't issue sandbox extension com.apple.app-sandbox.read-write for '/.../tmp/23720D22-BC1D-4E7B-A7AE-A1C8B0293F9E.txt': 
Invalid argument" UserInfo={NSDescription=couldn't issue sandbox extension com.apple.app-sandbox.read-write for '/.../tmp/23720D22-BC1D-4E7B-A7AE-A1C8B0293F9E.txt': Invalid argument}.

这是一个两步重现的过程:

  • 创建一个新的 Xcode 项目"基于文档的应用程序">
  • documentBrowser(_: , didRequestDocumentCreationWithHandler:)中键入此代码

    let newDocumentURL: URL? =
    URL(fileURLWithPath: NSTemporaryDirectory())
    .appendingPathComponent(UUID().uuidString)
    .appendingPathExtension("txt")
    // Set the URL for the new document here. Optionally, you can present a template chooser before calling the importHandler.
    // Make sure the importHandler is always called, even if the user cancels the creation request.
    if newDocumentURL != nil {
    print(newDocumentURL!)
    try! "My file content".write(to: newDocumentURL!, atomically: true, encoding: .utf8)
    importHandler(newDocumentURL, .move)
    } else {
    importHandler(nil, .none)
    }
    

在iOS 13模拟器上启动它,创建一个新文档,然后打印出错误,没有任何其他反应。

如果您在iOS 12上执行相同的代码,它可以完美运行,文件将被移动并由应用程序打开。

问题发生在iOS 13 beta 7上,无论是由Xcode 11 beta 7还是Xcode 10.3编译

的知道吗?

编辑:当您在文档目录而不是临时目录中创建文件时,问题仍然会出现:

FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]

编辑2:Xcode 11 GM(11A419c(仍然存在问题

编辑3:问题仅存在于模拟器上。在装有iOS 13 GM的设备上,UIDocumentBrowserViewController按预期工作。

编辑4:问题仍然存在于具有官方Xcode 11版本11A420a(又名GM Seed 2(的模拟器上。

编辑5:问题只发生在莫哈韦,卡特琳娜似乎没有

我已经验证了在Mac OS Mojave上运行的Xcode 11.1 GM存在该错误。

在 Catalina Beta 9 上运行时不会出现此问题。(FWIW 我在 Parallels 虚拟机中运行了 Catalina Beta 9,因为我不知道它是否足够稳定,可以升级到生产工作。

寻找解决方法,如果我找到任何解决方法,将发布(但请注意,这不是我的专业领域,只是根据事实证明是正确的预感进行的。

您可能希望更新您提交的雷达,以表明这可能是特定于莫哈韦的。

相关内容

最新更新