UIDocumentBrowserViewController's revealDocumentAtURL:importIfNeeded:completion: method never imports the url when needed

Originator:appsolutelyfun
Number:rdar://7058827 Date Originated:August 17, 2019
Status:open Resolved:no
Product:UIDocumentBrowserViewController Product Version:iOS 12.4
Classification:UIKit Reproducible:yes
 
On an iPad Pro (9.7-inch) running iOS 12.4, calls to the UIDocumentBrowserViewController's revealDocumentAtURL:importIfNeeded:completion: method fail to import the url even when the importIfNeeded parameter is set to YES.

Steps to reproduce:
(1) Tap on a file attachment in the Mail app, and select "copy to <appName>" in the resulting share menu.
(2) The revealDocumentAtURL:importIfNeeded:completion: method is called in <appName>, but even when the importIfNeeded parameter is set to YES, the url is not imported.  Apple's documentation indicates that "If importIfNeeded is YES, the document browser calls its delegate's documentBrowser:didImportDocumentAtURL:toDestinationURL: method (or its documentBrowser:failedToImportDocumentAtURL:error: method, if an error occurred) before calling the completion handler."  Contrary to the documentation, neither of those importing methods is ever called, and the url that is opened by the app-being-imported-into (in the revealDocumentAtURL's completion handler) is the url associated with the file attachment in the Mail app, rather than any url imported into the app's container.

Comments

Further investigation made me realize that the file attachment from Mail was failing to be imported into my app because (as the attachment was a file of the document type associated with my app) Mail had already imported it into my app's container-- specifically, into the user's Documents/Inbox directory-- when the file was shared with my app from Mail. This behavior, I found out, is described in https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW2.

Unfortunately, that "mail attachment importing into Documents/Inbox" behavior is not mentioned in any of the places that developers are initially likely to look when they add functionality for importing urls into a document-based app using UIDocumentBrowserViewController. In particular, it is not mentioned in...

(1) The "Enabling Document Sharing" article (https://developer.apple.com/documentation/uikit/view_controllers/adding_a_document_browser_to_your_app/enabling_document_sharing)

(2) The documentation for either UIApplication's openURL:options:completionHandler: method or UIDocumentBrowserViewController's revealDocumentAtURL:importIfNeeded:completion: method.

It would be good for the documentation for (1) and (2) to be updated to reflect the Documents/Inbox directory storage of files from outside the app (specifically, mail attachments) shared with the app. (It would also be good to mention in the (1) and (2) documentation that if the files at the imported urls are to be edited, they need to be moved out of the Documents/Inbox directory first.)

By appsolutelyfun at Aug. 18, 2019, 11:12 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!