我有一个WKWebview,它显示一个页面,该页面的代码总的来说是一个。我要在用户选择文件时进行一些处理。因此,我为可用的选择器(图像和文档)设置了一个委托,我将处理输出。我保存了原始委托,当我的代码被调用并且处理完成时,我将其回调,以便将URL返回到Webview。
此流程对于ImagePicker效果很好。问题是当我为UIDocumentPicker调用原始委托时。抛出
*-[WKFileUploadPanel documentPicker:didPickDocumentsAtURLs:]:无法识别的选择器已发送给实例*
即使未进行任何处理(如此处的片段所示),此操作也会恢复。 数据有效(调试时可以看到URL值)。
自然也只有在HTML端也有处理时才选择不调用原始委托进行处理。
UIDocumentPickerViewController* originalDocumentPicker;
id<UIDocumentPickerDelegate> documentPickerOriginalDelegate;
-(void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
if ([viewControllerToPresent class] == [UIDocumentPickerViewController class])
{
originalDocumentPicker = (UIDocumentPickerViewController*)viewControllerToPresent;
documentPickerOriginalDelegate = originalDocumentPicker.delegate;
[originalDocumentPicker setDelegate:self];
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
} else {
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
}
}
// delegate for UIDocumentPickerViewController
- (void)documentPicker:(UIDocumentPickerViewController *)controller
didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls
{
if (@available(iOS 11.0, *)) {
@try{
[documentPickerOriginalDelegate documentPicker:originalDocumentPicker didPickDocumentsAtURLs:urls];
}
@catch (NSException * e) {
NSLog(@"Error %@", e.reason);
}
} else {
// Fallback on earlier versions
NSLog(@"iOS 10-");
}
}
关于如何克服这一点的任何想法?