gpt4 book ai didi

ios - 如何快速访问云驱动器以将文件导入我的应用程序?

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:25 24 4
gpt4 key购买 nike

我想通过单击按钮从 iCloud、google drive 和 dropbox 等云服务获取文档(如下面的 WhatsApp 屏幕截图),有人知道如何快速完成吗?提前致谢

enter image description here

最佳答案

根据您项目的能力。首先启用 iCloud 服务和 key 共享,在你的类中导入 MobileCoreServices,最后在你的 UIViewController 中扩展以下三个类:

UIDocumentMenuDelegate,UIDocumentPickerDelegate,UINavigationControllerDelegate

实现以下功能:

 public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
let myURL = url as URL
print("import result : /(myURL)")
}


public func documentMenu(_ documentMenu:UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
}


func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("view was cancelled")
dismiss(animated: true, completion: nil)
}

如何调用所有这些?将以下代码添加到您的点击功能..

func clickFunction(){

let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)
}

点击您的按钮。将弹出以下菜单..

MenuPicker

以 DropBox 为例。单击任何项​​目。您将被重定向回您的应用,并且该 URL 将记录在您的终端中。

enter image description here

根据您的需要操作文档类型。在我的应用程序中,用户只允许使用 Pdf。所以,适合自己。

kUTTypePDF

此外,如果您想定制自己的菜单栏。添加如下代码,在handler中自定义自己的函数

        importMenu.addOption(withTitle: "Create New Document", image: nil, order: .first, handler: { print("New Doc Requested") })

enter image description here

好好享受吧。

关于ios - 如何快速访问云驱动器以将文件导入我的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38581723/

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