背景
用webview打開一個h5嵌洼,比如長按圖片時彈出系統(tǒng)alertVC案疲,平時沒有發(fā)現(xiàn)什么問題封恰,但如果此時你webview控制器是present呈現(xiàn)的話麻养,會發(fā)現(xiàn)奇怪的bug。alertVC__dismiss__時诺舔,控制器也會奇怪的跟著dismiss鳖昌。當時看到這個情況真的是震驚了,打斷點會發(fā)現(xiàn)調用兩次dismiss?(網上查到的很多是多次低飒,不知道是如何復現(xiàn)的)许昨,查看調用堆棧覺得是WKActionSheet搞的鬼。
解決過程
問題確定
首先確定的是褥赊,這是一個bug糕档,官方也已經進行修復,然而在Xcode10.2拌喉,iOS12還會出現(xiàn)問題速那,不造為什么(手動懵逼)俐银。
2018-03-12 Wenson Hsieh wenson_hsieh@apple.com
REGRESSION(r211643): Dismissing WKActionSheet should not also dismiss its presenting view controller
https://bugs.webkit.org/show_bug.cgi?id=183549
<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:]):
解決方案
- push這個包裹webview的vc
- 子類繼承UINavigationController并包裹vc,重寫dismissViewControllerAnimated方法
override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) {
if (self.presentedViewController != nil) {
super.dismissViewControllerAnimated(flag, completion: completion)
}
}
參考
https://webkit.googlesource.com/WebKit/+/master/Source/WebKit/ChangeLog