我正在使用 UIDocumentInteractionController 将指定 URL 的文档保存到 iCloud Drive,但问题是当我从 iCloud 保存/取消后切换回应用程序时,我的原始视图控制器不再存在,整个导航层次结构被删除并且显示了根视图控制器。
我正在从呈现视图控制器的视图控制器中呈现菜单中的选项。
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
}
}
从 iCloud 切换回来后,我应该怎么做才能保持在调用此方法的同一视图控制器上?