8

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

Zaphod
  • 6,758
  • 3
  • 40
  • 60
  • File a bug report. – matt Sep 05 '19 at 14:30
  • Just done it... – Zaphod Sep 05 '19 at 14:47
  • 2
    @matt have you reproduced the problem on your xcode? Because I can't believe all document based apps will be broken with the new iOS 13... Especially I can't find any workaround able to fix this behavior... – Zaphod Sep 09 '19 at 08:16
  • I'm seeing the same issue for quite some time. @Zaphod do you have the feedback number (or better a link to openradar) so I can dupe the bug report? – Tom Kraina Sep 11 '19 at 11:09
  • Here's the feedback : FB7213736 – Zaphod Sep 11 '19 at 12:07
  • It's not on http://www.openradar.me is it? – Tom Kraina Sep 11 '19 at 14:00
  • @TomKraina It seems not... – Zaphod Sep 12 '19 at 09:43
  • Issue still present in Xcode 11 GM 2. Openradar link: https://openradar.appspot.com/7250982 – OliverD Sep 18 '19 at 07:36
  • I'm seeing this too. FB7292722 https://www.dropbox.com/s/6opiur8r134rzkj/DBVCTest.zip?dl=0 – Steve Shepard Sep 18 '19 at 19:54
  • Seeing the same issue on Xcode 11.1 GM which was released a few hours ago. This is a major issue, DocumentBrowserViewController has been glitchy right from the start of iOS 13 :( – bright Sep 24 '19 at 20:30
  • 1
    I'm running on Mojave. Is everyone else on Mojave as well? My guess is that this does not occur on Catalina, and so the Apple developers must not have seen it in their testing – bright Sep 24 '19 at 20:36
  • Getting the same error here. Waiting for the new MacOS to come out, hopefully that will fix the issue. – Matt Bart Oct 02 '19 at 20:54
  • Interestingly the issue doesn't happen in their sample code. I'm trying to figure out the difference between that and my code. I'm on Catalina10.15.0 and Xcode 11.1 https://developer.apple.com/documentation/uikit/view_controllers/building_a_document_browser-based_app?language=objc – Nikolozi Oct 28 '19 at 13:22
  • @Nikolozi the difference seems to be only the os... On Mojave there's the problem, but it does not seem to happen in Catalina. – Zaphod Oct 29 '19 at 14:51
  • 1
    @Zaphod I think my issue was slightly different maybe. My app wasn't able to create new documents and was getting the above error. I followed Apple's code back when I first added that feature to my app & used to work fine. They must have updated sample code since then because it doesn't give the above error. I did some tweaks by closely following their code & now it works. However, their code (as well as my app) does fail when doing doc import. It can be a easily verified when dragging & dropping a file into the simulator from macOS. So, I think I might create a separate SO question for it. – Nikolozi Oct 30 '19 at 05:45
  • I have seen this bug on builds generated from Xcode 10 running in Catalina, so I don't believe it's as simple as it only occurs on Mojave. – Stoph Oct 31 '19 at 15:26

1 Answers1

0

I've verified that the bug exists with Xcode 11.1 GM running on Mac OS Mojave.

The issue does not occur when running on Catalina Beta 9. (FWIW I ran Catalina Beta 9 in a Parallels virtual machine because I don't know if it is stable enough to upgrade to for production work.)

Looking for workarounds, will post if I find any (but note this is not my area of expertise, just proceeded on a hunch that turned out to be correct.)

You may want to update the Radar you filed to indicate that this is probably specific to Mojave.

bright
  • 4,700
  • 1
  • 34
  • 59
  • I encountered this issue once with a build from Xcode 10.3 on Mojave (10.14.6). The app was running on on iPhone X running iOS 13.x (it was a week or two ago, so I may not have been on the latest version as of that date). Now, running the same build on the same device running iOS 13.1.3 I'm not seeing any issues. – Stoph Oct 31 '19 at 14:47
  • I have seen this bug on builds generated from Xcode 10 running in Catalina, so I don't believe it's as simple as it only occurs on Mojave. – Stoph Oct 31 '19 at 15:26
  • Even if the errors are the same, for the situations you've described, the people who see this in Mojave-but-not-Catalina certainly have a distinct problem… because the combination (Mojave + iOS 13/SIMMULATOR) is a regression that didn't happen before and doesn't happen after a macOS upgrade. – benc May 20 '20 at 06:27