【发布时间】:2020-06-05 14:55:30
【问题描述】:
我正在使用 Xcode 11.5 并在 WKWebView 中加载网页。我将文件访问权限设置为只读,这是我的应用功能列表。
这就是我的loadView 的样子
override func loadView() {
//Inject JS string to read console.logs for debugging
let configuration = WKWebViewConfiguration()
let action = "var originalCL = console.log; console.log = function(msg){ originalCL(msg); window.webkit.messageHandlers.iosListener.postMessage(msg); }" //Run original console.log function + print it in Xcode console
let script = WKUserScript(source: action, injectionTime: .atDocumentStart, forMainFrameOnly: false) //Inject script at the start of the document
configuration.userContentController.addUserScript(script)
configuration.userContentController.add(self, name: "iosListener")
//Initialize WKWebView
webView = WebView(frame: (NSScreen.main?.frame)!, configuration: configuration)
//Set delegates and load view in the window
webView.navigationDelegate = self
webView.uiDelegate = self
view = webView
}
当我在 iOS 上使用 Safari 并选择输入类型 = 文件时,对话框打开,但使用我的 macOS 应用程序使用 web 视图时它不起作用?我需要在我的应用程序上设置更多功能吗?我发现了一些文件输入的老问题,但它们似乎已经解决了?
【问题讨论】:
-
@Willeke 我使用 Swift 4,所以我认为这不能回答我的问题
-
“您只需要实现 UIDelegate”和指向RunOpenPanel Delegate 的链接是否回答了您的问题?
标签: swift xcode macos progressive-web-apps