我有一个WKWebview加载基于Web的用户界面,我希望用户能够从他们的iCloud文档上传文件。我已授予正确的权限,并且可以浏览iCloud文档。然而,当我选择一个文件或点击取消按钮,以及解除我的WKWebview的父视图的文档选择器视图也被取消。从WKWebview解雇容器视图的iCLoud文档选择器
我试图追踪解雇路径。我100%确定我不打电话给我的观点解雇功能。
有没有人有任何想法是什么触发我的WKWebview容器解雇,以及如何防止它?
我有一个WKWebview加载基于Web的用户界面,我希望用户能够从他们的iCloud文档上传文件。我已授予正确的权限,并且可以浏览iCloud文档。然而,当我选择一个文件或点击取消按钮,以及解除我的WKWebview的父视图的文档选择器视图也被取消。从WKWebview解雇容器视图的iCLoud文档选择器
我试图追踪解雇路径。我100%确定我不打电话给我的观点解雇功能。
有没有人有任何想法是什么触发我的WKWebview容器解雇,以及如何防止它?
我在使用WKWebView的Objective-C和iOS11上遇到了同样的问题,并使用此解决方法解决了这个问题。你应该能够将其迁移到斯威夫特轻松:
这个视图控制器内部的视图控制器拥有添加此弱属性
@property (weak, nonatomic) UIDocumentPickerViewController *_Nullable docPickerPtr;
在相同的视图控制器内覆盖这两个方法UIViewController基本类的原始部分
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion
{
if ([viewControllerToPresent isKindOfClass:[UIDocumentPickerViewController class]])
{
_docPickerPtr = (UIDocumentPickerViewController*)viewControllerToPresent;
}
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
}
- (void)dismissViewControllerAnimated:(BOOL)flag
completion:(void (^)(void))completion
{
if (_docPickerPtr != nil && self.presentedViewController == nil)
{
NSLog(@">>>>>>>>>>>>PREVENT FROM DOING 2nd DISMISS!");
}
else
{
[super dismissViewControllerAnimated:flag completion:completion];
}
}
我们做的是:
有在UIDocumentPickerViewController
的错误。
1)保存对UIDocumentPickerViewController
的弱引用,内部任何视图控制器呈现UIDocumentPickerViewController
。 (这通常最终会被UINavigationController
,所以你可能要继承UINavigationController
来解决这个问题。)
///Due to a bug in UIDocumentPickerViewController we need to stop the UIDocumentPickerViewController from dismissing this navigation controller. Or at least provide control. This is a weak reference to a UIDocumentPickerController that this controller presents
weak var documentPicker: UIDocumentPickerViewController?
2)覆盖在UIViewController
这两个功能是呈现UIDocumentPickerViewController
//MARK: Overrides
override public func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
if self.presentedViewController == nil && self.documentPicker != nil {
self.documentPicker = nil
}else{
super.dismiss(animated: flag, completion: completion)
}
}
public override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
if viewControllerToPresent is UIDocumentPickerViewController {
self.documentPicker = viewControllerToPresent as? UIDocumentPickerViewController
}
super.present(viewControllerToPresent, animated: flag, completion: completion)
}
现在来自UIDocumentPickerViewController
的第二个电话将不会驳回呈现UIViewController
。