How can you get input file to work in a WKWebView?

2019-02-27 14:53发布

When you have a WKWebView in an OSX application, when you press a <input type="file"> button, you can't select a file from your harddisk. How would you enable this feature?

I heard that normally you use:

func webView(sender: WebView!, runOpenPanelForFileButtonWithResultListener resultListener: WebOpenPanelResultListener!)

Which is part of the WebUIDelegate but altho you set self.webView.UIDelegate = self it does not get fired.

2条回答
甜甜的少女心
2楼-- · 2019-02-27 15:20

Here is the 100% working solution for WKWebview "File Upload" Problem.

You just need to implement the UIDelegate:

- (void)webView:(WKWebView *)webView runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSArray<NSURL *> *URLs))completionHandler;

Follow this link for more description about this delegate: RunOpenPanel Delegate

查看更多
女痞
3楼-- · 2019-02-27 15:29
登录 后发表回答