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条)