UIDocumentBrowserViewController won't let me pick existing document

I'm following the process shown in WWDC 2017 session 229 and makde a UIDocumentBrowserViewController subclass. My app uses a document package and I've created the document type and exported the UTI. I can create a document from the UIDocumentBrowserViewController by clicking the plus button and I've verfied by cd'ing into the Simulator directories that the document is created properly (the directory is created and the files in the directory for the document are created correctly). But when I tap on existing document in the UIDocumentBrowserViewController, the documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) method is not called.


Any ideas on what I could be doing wrong?


Thanks,

Dave

HI Dave,


I had the same problem when trying to bring an existing document app into the new template.

What fixed it for me was making sure the structure of the entries in the Document Types and Exported UTIs was exactly as shown in the session slides, which wasn't the same as my existing app. In particular the Additional exported UTI properties area that seems to be a dictionary containing an array containing one item that's the file extension of your files.


Once I'd got it exactly matching the document browser started showing my files as white graphic with a corner turned over like a page rather than just a white rectangle and didPickDocumentURLs was called.


Hope this helps.

-Chris

Thanks for the reply Chris. Yes, I have it as a dictionary with an arry of one item just like that. It also shows up as a white graphic with a corner turned over, but tapping on it does nothing.


Are you using a file package (i.e., is your document a directory structure with files in the directory)?


In the Exported UTIs, I have "Conforms to" set to com.apple.package and I've also tried adding both public.content and public.composite-content since it is a file package/directory.


This is an existing app that works on iOS 10 so when I would use the UIDocument open method, it works just fine (i.e., I'm not getting something set up correctly here or there is a bug).


Thanks,

Dave

My app is just using a single file with data created through NSCoding and NSKeyedArchiver.

Looks Ike I spoke too soon with it working though.


I've created a template file using my data format which gets copied as in the wwdc session when a new document is created. It does get copied into the documents directory, it shows up in the doc browser and when I tap it I get a call to didPickDocumentURLs. All good, until I change the data and trigger the document to save. When that happens I get a big splurge of errors in the log and something seems to go wrong with the file. Once this has happened I can't open the file again or even create a new one.


I hoped that this was just some issue with my app or data so I started again from scratch with the XCode template and a very basic data file that saves just one integer. Same problem. I've checked the contents of the template file and post save data file and they both look perfectly fine, the saved one just doesn't load anymore!


These are the errors that I get. Are you getting anything similar? The old xcode 8 version of my app was working with documents in almost the same way and doesnt show any errors like this.


2017-06-19 20:37:33.182683+0100 docTestios11[93120:1101660] [default] [ERROR] Could not get attribute values for item file:///Users/chris/Library/Developer/CoreSimulator/Devices/45365600-9AD0-475B-B585-9A240FD4BCED/data/Containers/Data/Application/EB40D1E0-4D5B-4023-BBB3-18765B5DAC3E/Documents/Template.myfile. Error: Error Domain=LocalStorageFileProvider.LocalFileProviderError Code=0 "(null)"


-Chris

Looks like my problem is definitely related to it being a file package. I have a second document type that is not a file package/directory and the UIDocumentBrowserViewController calls the delegate method documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) when I tap on it.


So am I doing something wrong (i.e., missing an extra step necessary for file packages) or is UIDocumentBrowserViewController broken for file packages and I need to file a bug?


Thanks,

Dave

For any Apple engineers reading this, the bug still exists in beta 2 and I have submited a bug report: rdar://32912183

Hi Dave,

I'll have a go with beta 2 as soon as I can to see if it fixes the problems I'm having.


Quick recap as my reply to your post describing the issues I'm having has been stuck in moderation for 3 days!


All was working for me until the document performed an auto save and then the document browser wouldn't load it anymore even though the file contents seemed fine. I'm using a basic single file using Data and KeyedArchiver.

I even redid the whole thing without any of my app using just a super basic file that saved just one Integer. Followed the WWDC session and I still get the same result. It works, then the doc saves the file then it doesn't work anymore.


-Chris

Sill the same issues in Beta 2.

Once UIDocument.updadeChangeCount(.done) is called the file saves with errors and then can't be opened via the document browser anymore.


I'll repost the errors I get in a separate reply incase that's what's causing the multi-day wait with the moderators.


-Chris

Errors on saving look like this


[default] [ERROR] Could not get attribute values for item file:///Users/cmcclure/Library/Developer/CoreSimulator/Devices/C0346BD3-47EF-44DA-8E73-DE48B162566F/data/Containers/Data/Application/810E54D6-F348-4502-8409-4094918B9F85/Documents/Template%202.myfile. Error: Error Domain=LocalStorageFileProvider.LocalFileProviderError Code=0 "(null)"

I'm in the same boat here. Can't open my docs after UIdocument.save is called, either because of autosave or the doc being closed.

I'd suggest you both file a bugreport and mention mine (#32912183) as I also posted on Apple's cocoa-dev email list (which is going away soon) and an Apple employee said he'd make certain the right people look at it.


Dave

Thanks Dave and Steve,

I've created a bug report (32947101)


-Chris

Have you tried it on an actual iPad? My student who co-developed the app with me put the iOS 11 beta 2 on his iPad and opening existing documents seems to work fine on the device (i.e., the problem may only occur in the iOS simulator on the Mac). We still did have trouble using the UIDocumentBrowserViewController to move existing documents between folders but creating and opening appears to work on the device.

In case you missed my one reply above. I tried it on my co-developer's iPad (that he upgraded to iOS 11 beta 2) and opening files on the device seems to work, but it doesn't work on the simulator. We still can't move files.

Any update in Beta 3? I haven't installed the beta on my devices yet, since they are my working tools! I see slightly different behavior in the simulator...now there is an icon on my documents, but I still can't open previously created and saved documents.

I haven't put beta 3 on my iPad but I concur that it still doesn't work in the simulator. I don't think my co-developer has tried it with beta 3 on his iPad yet.

UIDocumentBrowserViewController won't let me pick existing document
 
 
Q