I have a very strange problem with UIDocumentBrowserViewController
when testing on iOS 13. The importHandler(newDocumentURL, .move)
seems to crash without any reason :
[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}.
Here is a two step process to reproduce :
- Create a new Xcode project "Document Based App"
Type in this code in the
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) }
Launch it on an iOS 13 simulator, create a new document, and the error is printed out and nothing else happens.
If you execute the same code on iOS 12, it perfectly works, the file is moved and is opened by the app.
The problem occurs on iOS 13 beta 7, wether it's compiled by Xcode 11 beta 7 or Xcode 10.3
Any idea?
EDIT: The problem still occurs when you create the file in the document directory instead of the temporary directory :
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
EDIT 2: The problem still exists with Xcode 11 GM (11A419c)
EDIT 3: The problem persists only the simulator. On device with iOS 13 GM, UIDocumentBrowserViewController
works as expected.
EDIT 4: Problem still present on simulators with official Xcode 11 release 11A420a (aka GM Seed 2.)
EDIT 5: Problem only occurs on Mojave and seems to be absent on Catalina