Reputation: 4821
Apple's documentation is thin on the subject of UIDocumentBrowserViewController
-based apps that want to support opening multiple documents simultaneously.
I'd like to enable this, so that the user can copy/paste between two or more documents easily, without having to exit back to the document browser, which is not a fluid experience on iOS.
Apart from a terse description of the allowsPickingMultipleItems
property, I couldn't find anything.
For a single document view, Apple recommends a modal view, but doesn't say anything else.
Questions
Upvotes: 0
Views: 1180
Reputation: 21
I am a relatively new iOS developer, so take all of this with a grain of salt.
The following worked for me:
URL
, and another that can take an input of [URL]
. These ViewControllers must then show the document(s) associated with the URL(s) on screen.
documentBrowser(_:, didPickDocumentURLs:)
, check how many URL
s were passed in, and present one of the above ViewControllers (as appropriate)example:
class DocumentBrowserViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
allowsDocumentCreation = false
allowsPickingMultipleItems = true
// -snip-
}
// MARK: UIDocumentBrowserViewControllerDelegate
// -snip-
func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) {
if documentURLs.count < 1 {
return
} else if documentURLs.count == 1 {
presentDocument(at: documentURLs[0])
} else {
presentDocuments(at: documentURLs)
}
}
// -snip-
// MARK: Document Presentation
func presentDocument(at documentURL: URL) {
// present one document
// example:
// let vc = SingleDocumentViewController()
// vc.documentURL = documentURL
// present(vc, animated: true, completion: nil)
}
func presentDocuments(at documentURLs: [URL] {
// present multiple documents
// example:
// let vc = MultipleDocumentViewController()
// vc.documentURLs = documentURLs
// present(vc, animated: true, completion: nil)
}
}
To answer your additional questions:
Some caveats:
Note:
documentBrowser(_:, didPickDocumentURLs:)
will be renamed documentBrowser(_: didPickDocumentsAt:)
in iOS 12
Upvotes: 2