1. self.webView.UIDelegate = self;
2. 实现代理在本地打开NSOpenPanel,并将解决回调回去
- (void)webView:(WKWebView*)webView runOpenPanelWithParameters:(WKOpenPanelParameters*)parameters initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void(^)(NSArray *_NullableURLs))completionHandler{
NSOpenPanel* panel = [NSOpenPanel openPanel];
if(@available(macOS10.12, *)){
panel.allowsMultipleSelection = parameters.allowsMultipleSelection;
}else{
[panelsetAllowsMultipleSelection:NO]; //是否允许多选file
}
if(@available(macOS10.13.4, *)){
panel.canChooseDirectories = parameters.allowsDirectories;
}else{
panel.canChooseDirectories=NO; //是否允许选目录
}
panel.allowedFileTypes = @[@"png", @"jpg", @"BMP", @"TIFF"];//图片类型
NSModalResponseresult = [panelrunModal];
if(result ==NSModalResponseOK){
completionHandler([panelURLs]);
}else{
completionHandler(nil);
}
// [panel beginWithCompletionHandler:^(NSModalResponse result) {
// if (result == NSModalResponseOK) {
// completionHandler([panel URLs]);
// }
// }];
}