WKWebview的bug

背景

用webview打开一个h5,比如长按图片时弹出系统alertVC,平时没有发现什么问题,但如果此时你webview控制器是present呈现的话,会发现奇怪的bug。alertVC__dismiss__时,控制器也会奇怪的跟着dismiss。当时看到这个情况真的是震惊了,打断点会发现调用两次dismiss(网上查到的很多是多次,不知道是如何复现的),查看调用堆栈觉得是__WKActionSheet__搞的鬼。

解决过程

问题确定

首先确定的是,这是一个bug,官方也已经进行修复,然而在Xcode10.2,iOS12还会出现问题,不造为什么(手动懵逼)。

2018-03-12 Wenson Hsieh wenson_hsieh@apple.com REGRESSION(r211643): Dismissing WKActionSheet should not also dismiss its presenting view controller bugs.webkit.org/show_bug.cg… rdar://problem/34960698 Reviewed by Andy Estes. Fixes the bug by dismissing the presented view controller (i.e. the action sheet or the view controller being presented during rotation) rather than the presenting view controller. Test: ActionSheetTests.DismissingActionSheetShouldNotDismissPresentingViewController * UIProcess/ios/WKActionSheet.mm: (-[WKActionSheet doneWithSheet:]):

解决方案
  1. push这个包裹webview的vc
  2. 子类继承UINavigationController并包裹vc,重写dismissViewControllerAnimated方法
override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) {
    if (self.presentedViewController != nil) {
        super.dismissViewControllerAnimated(flag, completion: completion)
    }
}
复制代码

参考

stackoverflow.com/questions/4…

stackoverflow.com/questions/3…

webkit.googlesource.com/WebKit/+/ma…

其他

简书 MyBlog

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值