The issue involves sharing a document with my app using the "Copy to ...".
The result of that action is a call to:
//TODO: This is where we save to the documents folder I beleive.
func application(_ app: UIApplication, open inputURL: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Ensure the URL is a file URL
guard inputURL.isFileURL else { return false }
print(#function)
// Reveal / import the document at the URL
guard let documentBrowserViewController = window?.rootViewController as? DocumentBrowserViewController else {
print("DocumentBrowserViewController needs to be RootViewController")
return false
}
documentBrowserViewController.revealDocument(at: inputURL, importIfNeeded: true) { (revealedDocumentURL, error) in
//TODO: Handle error with alert
if let error = error {
print("Error: Failed to reveal the document at URL \(inputURL) with error: '\(error)'")
} else {
print("Success.")
}
// Present the Document View Controller for the revealed URL
//documentBrowserViewController.presentDocument(at: revealedDocumentURL!)
}
return true
}
The print statements show the block: documentBrowserViewController.revealDocument
gets executed without error.
Per the Documentation:
If importIfNeeded is true, the document browser calls its delegate's documentBrowser(:didImportDocumentAt:toDestinationURL:) method (or its documentBrowser(:failedToImportDocumentAt:error:) method, if an error occurred) before calling the completion handler.
Neither of the 2 methods are getting called though.
NOTES:
- I have set the documentBrowserViewController as it's own delegate.
- I am not alone. Apple Forum.
Am I misunderstanding the API?
My goal is to save the file to the users Documents when it is imported from an external app using ("copy to"). My plan was to do it in:
documentBrowser(_:didImportDocumentAt:toDestinationURL:)