WKWebview的iCLoud文档选择器关闭了容器视图 [英] iCLoud document picker from WKWebview dismissing container view

查看:165
本文介绍了WKWebview的iCLoud文档选择器关闭了容器视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WKWebview,它加载基于Web的UI,我希望用户能够从其iCloud文档中上传文件.我已授予正确的权限,并且能够浏览iCloud文档.但是,当我选择一个文件或单击取消"按钮时,同时关闭我的WKWebview的父视图的文档选择器视图也会被关闭.

I have a WKWebview loading a web based UI where I would like users to be able to upload a file from their iCloud documents. I have granted the correct permissions and I am able to browse the iCloud documents. However when I either select a file or click the cancel button, as well as the document picker view dismissing the parent view of my WKWebview is also dismissed.

我尝试跟踪解雇路径.我100%确信我不会在视图中调用dismiss函数.

I have tried to track the dismiss path. I am 100% sure I am not calling the dismiss function on my view.

是否有人知道是什么触发了我的WKWebview容器上的关闭,以及如何防止它发生?

Does anyone have any idea what is triggering the dismiss on my WKWebview container and how to prevent it?

推荐答案

UIDocumentPickerViewController中存在错误.

1)将弱引用保存到视图控制器显示UIDocumentPickerViewController的内容中的UIDocumentPickerViewController. (这通常以UINavigationController结尾,因此您可能必须将UINavigationController子类化以解决此问题.)

1) Save weak reference to UIDocumentPickerViewController inside what ever view controller presents the UIDocumentPickerViewController. (This usually end up being a UINavigationController so you will probably have to subclass UINavigationController to fix this.)

///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)覆盖呈现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.

Now the second call from the UIDocumentPickerViewController will not dismiss the presenting UIViewController.

这篇关于WKWebview的iCLoud文档选择器关闭了容器视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆