swift - 在 Mac Catalyst 中使用文档浏览器 View Controller

标签 swift browser document mac-catalyst uidocumentbrowserviewcontroller

我刚刚开始试用 Catalyst。我的应用程序是一个基于文档浏览器的应用程序。

单击适当的按钮时,确实启动了原装 MacOS Finder 对话框。当 Finder 对话框出现时,主应用程序窗口完全消失,除非我在 IB 中选择文档浏览器 View Controller 以“自动”模式出现。

取消操作确实会返回主窗口。

但是,选择一个文件将产生一个空白屏幕并且没有结果。稍微调试一下,发现没有调用任何文件选择函数,我已经实现了所有这些函数:

func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) {...}

func documentBrowser(_ controller: UIDocumentBrowserViewController, didImportDocumentAt sourceURL: URL, toDestinationURL destinationURL: URL) {...}

func documentBrowser(_ controller: UIDocumentBrowserViewController, failedToImportDocumentAt documentURL: URL, error: Error?) {...}

Catalyst 中是否使用了其他函数或句柄?我在文档中找不到任何内容。

编辑: 我应该澄清一下,我操纵应用程序在 DocumentBrowserViewController 之前呈现 DocumentViewController,尽管 Apple 要求 DocumentBrowserViewController 是初始 View Controller 。我通过更改应用程序委托(delegate)来做到这一点:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

...

// Set the documentViewController to appear first
    self.window = UIWindow(frame: UIScreen.main.bounds)

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let initialViewController = storyboard.instantiateViewController(withIdentifier: "main")

    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()

    return true
}

把它拿出来仍然没有任何改变。从文档浏览器模板创建的默认项目似乎确实有效。什么可以阻止调用这些方法?

最佳答案

我建议也实现 func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL])

关于swift - 在 Mac Catalyst 中使用文档浏览器 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58322189/

相关文章:

ios - 如何在 xcode 中为使用 swift 制作的 spritekit 游戏创建主菜单?

ios - 对来自 firebase 的 tableView 数据进行排序

swift - 无论如何只能访问 child 字典的值(value)?

javascript - THREE.js 不在浏览器中呈现

node.js - 按 MongoDB 中具有相同字段的文档数排序/分组

swift - 快速扩展通用对象数组

javascript - 从浏览器访问 ArangoDB 数据

browser - 为什么网页浏览器中会出现问号?

java 将元素转换为字符串

xcode - 文档类型与导出和导入的 UTI