I am using UIDocumentInteractionController to save the document at specified URL to iCloud Drive, but the problem is that when I switch back to the app after saving/cancel from iCloud, my original view controller is no longer present, the entire navigation hierarchy is removed and the root view controller is shown.
I am presenting the options in the menu from a view controller that is presented view controller.
extension ADDTextChatViewController: AddReceiverFileDelegate {
func downloadTapped(url: String?, cell: AddReceiverTableViewCell) {
guard let urlString = url else {return}
shareAction(withURLString: urlString, cell: cell)
}
}
extension ADDTextChatViewController {
func share(url: URL, cell: AddReceiverTableViewCell) {
documentInteractionController.url = url
documentInteractionController.uti = url.typeIdentifier ?? "public.data, public.content"
documentInteractionController.name = url.localizedName ?? url.lastPathComponent
documentInteractionController.presentOptionsMenu(from: cell.btnDownload.frame, in: view, animated: true)
}
func shareAction(withURLString: String, cell: AddReceiverTableViewCell) {
guard let url = URL(string: withURLString) else { return }
URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data, error == nil else { return }
let tmpURL = FileManager.default.temporaryDirectory
.appendingPathComponent(response?.suggestedFilename ?? "fileName.png")
do {
try data.write(to: tmpURL)
} catch { print(error) }
DispatchQueue.main.async {
self.share(url: tmpURL, cell: cell)
}
}.resume()
}
}
extension URL {
var typeIdentifier: String? {
return (try? resourceValues(forKeys: [.typeIdentifierKey]))?.typeIdentifier
}
var localizedName: String? {
return (try? resourceValues(forKeys: [.localizedNameKey]))?.localizedName
}
}
What shall I do in order to remain on the same view controller from which I called this method, after switching back from iCloud?