swift - Unable to Specify File Types in WKWebView Using runOpenPanelWithParameters on macOS - Stack Overflow

I am write a wkwebview application in macos where I want to enable file upload to my website loaded in

I am write a wkwebview application in macos where I want to enable file upload to my website loaded in wkwebview. I found few articles telling to use runOpenPanelWithParameters which runs for me but I stuck in a problem.

Problem:

The method works to open the file dialog, but I'm stuck on how to properly handle the file(s) selected by the user and upload them to my website. i.e: If website only want img upload, from chrome it fade out files other then img, I want to achieve same in wkwebview.

- (void)webView:(WKWebView *)webView runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSArray<NSURL *> * _Nullable))completionHandler {
    NSOpenPanel *openPanel = [NSOpenPanel openPanel];
    openPanel.canChooseFiles = YES;
    openPanel.canChooseDirectories = NO;
    openPanel.allowsMultipleSelection = parameters.allowsMultipleSelection;

    [openPanel beginWithCompletionHandler:^(NSModalResponse result) {
        if (result == NSModalResponseOK) {
            completionHandler(openPanel.URLs);
        } else {
            completionHandler(nil);
        }
    }];
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745271564a4619778.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信