gpt4 book ai didi

ios - 在 Swift 的文档选择器 View Controller 中显示云存储选项

转载 作者:行者123 更新时间:2023-11-28 15:01:51 31 4
gpt4 key购买 nike

我正在尝试在我的文档选择器 View Controller 中打开云存储应用程序。我已经应用了文档选择器 View Controller 的所有必要委托(delegate)方法。当我点击一个按钮时,它会显示文档选择器 View ,但其中未显示应用程序图标及其名称。它仅在选择器 View 中显示浏览选项。我想在前面显示所有存储。我的代码是这样的,

@IBAction func cloudBtnTapped(_ sender: Any) {

let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF),String(kUTTypeZipArchive), String (kUTTypePNG), String (kUTTypeJPEG), String (kUTTypeText),String (kUTTypePlainText)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .fullScreen
self.present(importMenu, animated: true, completion: nil)
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {

cico = url as URL as NSURL
print("The Url is : /(cico)", cico)

// Start background thread so that image loading does not make app unresponsive
DispatchQueue.global(qos: .userInitiated).async {

let imageData:NSData = NSData(contentsOf: self.cico as URL)!

// When from background thread, UI needs to be updated on main_queue
DispatchQueue.main.async {
let image = UIImage(data: imageData as Data)
self.image1.image = image
}
}

do {
let weatherData = try NSData(contentsOf: cico as URL, options: NSData.ReadingOptions())
let activityItems = [weatherData]
let activityController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
if UI_USER_INTERFACE_IDIOM() == .phone {
self.present (activityController, animated: true, completion: {
print("Hello")
})
}
else {
let popup = UIPopoverController(contentViewController: activityController)
popup.present(from: CGRect(x: CGFloat(self.view.frame.size.width / 2), y: CGFloat(self.view.frame.size.height / 4), width: CGFloat(0), height: CGFloat(0)), in: self.view, permittedArrowDirections: .any, animated: true)
}
} catch {
print(error)
}
//optional, case PDF -> render
//displayPDFweb.loadRequest(NSURLRequest(url: cico) as URLRequest)
}


func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {

documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}

func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {

print(" cancelled by user")

// dismiss(animated: true, completion: nil)
_ = navigationController?.popViewController(animated: true)
}

当点击按钮时,它会显示这样的文档选择器 View ,
enter image description here

但我想要这个 .像这样的选择器 View ,
enter image description here

我怎样才能显示这个?

最佳答案

UIDocumentMenuViewController 会自动显示诸如 dropbox、google drive 之类的选项,如果你已经在你的设备上安装了它,否则它不会显示。

您还可以通过以下方法向菜单添加一些自定义选项...addOptionWithTitle:image:order:handler: 方法。

您可以使用 UIDocumentPickerViewController 从"file"应用或 iCloud Drive 获取文件。

let options = [kUTTypePDF as String, kUTTypeZipArchive  as String, kUTTypePNG as String, kUTTypeJPEG as String, kUTTypeText  as String, kUTTypePlainText as String]

let documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(documentTypes: options, in: .import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .fullScreen
self.present(documentPicker, animated: true, completion: nil)


extension YourViewController: UIDocumentPickerDelegate {

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {

//from url you can get selected item
}
}

关于ios - 在 Swift 的文档选择器 View Controller 中显示云存储选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48825051/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com