admin管理员组

文章数量:1418113

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);
        }
    }];
}

本文标签: swiftUnable to Specify File Types in WKWebView Using runOpenPanelWithParameters on macOSStack Overflow