UI/WKWebView|UI/WKWebView input file标签dismiss bug处理

iOS WebView 用标签打开系统相册会出现dismiss掉当前视图的bug,这是因为点击系统弹出的alertController时,会多次调用dismiss(不知原因)。如果WebView自己或者根视图是通过present出来的,则会被dismiss掉,而用navigation push出来的则没有问题。
UI/WKWebView|UI/WKWebView input file标签dismiss bug处理
文章图片
解决办法

  1. 不使用present方式展示WebView
  2. 用自定义navigation套着WebView,然后override dismiss方法
class WebViewNavigationController: UINavigationController { override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { // fix webview input-file dismiss-twice bug if let _ = self.presentedViewController { super.dismiss(animated: flag, completion: completion) } } }let webViewController let nav = WebViewNavigationController(rootViewController: webViewController) self.present(nav, animated: true, completion: nil)

【UI/WKWebView|UI/WKWebView input file标签dismiss bug处理】Read more
  • https://stackoverflow.com/questions/37380333/modal-view-closes-when-selecting-an-image-in-wkwebview-ios
  • https://stackoverflow.com/questions/35999551/uiimagepickercontroller-view-is-not-in-the-window-hierarchy
  • http://www.jianshu.com/p/284405e7313d
  • http://www.infocool.net/kb/IOS/201612/247812.html

    推荐阅读