在 iOS14 上释放 wkwebview 时,发送手势事件导致崩溃

Posted

技术标签:

【中文标题】在 iOS14 上释放 wkwebview 时,发送手势事件导致崩溃【英文标题】:Send gestures event cause crash when a wkwebview dealloced on iOS14 【发布时间】:2020-07-13 12:14:49 【问题描述】:

在我的应用程序中,推送到包含 wkwebview 的视图控制器并使用长按手势显示选择文本菜单,然后弹出视图控制器使 web 视图解除锁定。然后推送到另一个 web 视图控制器,发送手势到webview,然后崩溃。它发生在 ios 14 beta 2 上。我已经向苹果报告了这个错误。它以某种方式存在?

Date/Time:             2020-07-13 18:46:00.715 +0800
OS Version:            Mac OS X 10.15.5 (19F101)
Report Version:        12
Bridge OS Version:     4.5 (17P5300)
Anonymous UUID:        DC589A65-FAD9-1105-69E1-F841F6FEE2E3

Sleep/Wake UUID:       D3E2CB0D-6218-4CC0-85C5-86C8DAE0B4BC

Time Awake Since Boot: 240000 seconds
Time Since Wake:       33000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000022
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [50050]

VM Regions Near 0x22:
--> 
    __TEXT                 000000010f792000-000000010f796000 [   16K] r-x/r-x SM=COW  /Users/USER/Library/Developer/CoreSimulator/Devices/4CDD359F-0A7E-4E13-A2CE-0DA825D90269/data/Containers/Bundle/Application/D19A53D4-CA61-4FCA-9F2D-ECAEA1A0D9C3/TestWebView.app/TestWebView

Application Specific Information:
CoreSimulator 725.10 - Device: iPhone 8 (4CDD359F-0A7E-4E13-A2CE-0DA825D90269) - Runtime: iOS 14.0 (18A5319g) - DeviceType: iPhone 8

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x0000000110d38b88 objc_retain + 8
1   com.apple.UIKitCore             0x00000001219ec716 -[UIInputResponderController prepareToMoveKeyboardForInputViewSet:animationStyle:] + 348
2   com.apple.UIKitCore             0x00000001219eacdf -[UIInputResponderController setKeyWindowSceneInputViews:animationStyle:] + 623
3   com.apple.UIKitCore             0x00000001219eaa45 -[UIInputResponderController setInputViews:animationStyle:] + 200
4   com.apple.UIKitCore             0x00000001219ec000 -[UIInputResponderController setInputViews:animated:] + 88
5   com.apple.UIKitCore             0x00000001219ec067 -[UIInputResponderController setInputViews:] + 68
6   com.apple.UIKitCore             0x00000001219e98a9 __74-[UIInputResponderController _reloadInputViewsForKeyWindowSceneResponder:]_block_invoke.605 + 30
7   com.apple.UIKitCore             0x00000001219e94b2 -[UIInputResponderController _reloadInputViewsForKeyWindowSceneResponder:] + 3982
8   com.apple.UIKitCore             0x00000001219e8507 -[UIInputResponderController _reloadInputViewsForResponder:] + 148
9   com.apple.UIKitCore             0x0000000121fdb741 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 133
10  com.apple.UIKitCore             0x0000000121fd6af9 -[UIResponder becomeFirstResponder] + 806
11  com.apple.UIKitCore             0x00000001224df189 -[UIView(Hierarchy) becomeFirstResponder] + 145
12  com.apple.WebKit                0x000000010fed7f9c -[WKContentView(WKInteraction) becomeFirstResponderForWebView] + 136
13  com.apple.WebKit                0x000000010fac30c8 -[WKWebView(WKViewInternalIOS) becomeFirstResponder] + 133
14  com.apple.UIKitCore             0x00000001222870b7 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessaryActivatingSelection:] + 195
15  com.apple.UIKitCore             0x00000001222881e7 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) checkEditabilityAndSetFirstResponderIfNecessary] + 376
16  com.apple.UIKitCore             0x0000000122257e63 -[UITextIndirectNonEditableInteraction willBeginGesture] + 128
17  com.apple.UIKitCore             0x0000000121e16573 -[_UIKeyboardBasedNonEditableTextSelectionInteraction oneFingerForcePan:] + 1339
18  com.apple.UIKitCore             0x0000000121aed683 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 49
19  com.apple.UIKitCore             0x0000000121af7904 _UIGestureRecognizerSendTargetActions + 100
20  com.apple.UIKitCore             0x0000000121af41cb _UIGestureRecognizerSendActions + 294
21  com.apple.UIKitCore             0x0000000121af352a -[UIGestureRecognizer _updateGestureForActiveEvents] + 725
22  com.apple.UIKitCore             0x0000000121ae5a72 _UIGestureEnvironmentUpdate + 2652
23  com.apple.CoreFoundation        0x0000000110dfc277 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24  com.apple.CoreFoundation        0x0000000110df6dae __CFRunLoopDoObservers + 487
25  com.apple.CoreFoundation        0x0000000110df72df __CFRunLoopRun + 1137
26  com.apple.CoreFoundation        0x0000000110df6aba CFRunLoopRunSpecific + 538
27  com.apple.GraphicsServices      0x00000001139fcdb3 GSEventRunModal + 139
28  com.apple.UIKitCore             0x0000000121fa27fe -[UIApplication _run] + 912
29  com.apple.UIKitCore             0x0000000121fa7e1e UIApplicationMain + 1570
30  jkl.TestWebView                 0x000000010f793fa2 main + 114 (main.m:17)
31  libdyld.dylib                   0x0000000119d4395d start + 1

Thread 1:


【问题讨论】:

这是在ios14模拟器上复制的,iphone也崩溃了。 【参考方案1】:

我遇到了同样的问题。

似乎 -[UIInputViewSet restoreableResponder] 返回一个野指针。这个属性不弱也不强。 我在 -[UIInputViewSet restoreableResponder] 和 -[UIInputViewSet setRestorableResponder:] 中添加了符号断点,汇编代码显示它们既没有 store_weak 也没有 store_strong 代码。

我使用了一种解决方法,挂钩 -[UIInputViewSet restoreableResponder] 并返回 nil。也许它会导致另一个问题。但经过测试,它似乎运行良好。

【讨论】:

以上是关于在 iOS14 上释放 wkwebview 时,发送手势事件导致崩溃的主要内容,如果未能解决你的问题,请参考以下文章

iOS 14 上的 WKWebView 仅在显着延迟后加载内容

iOS学习笔记14-网络WebView

在 iOS 中,当用户滚动浏览 WKWebView 时,如何检测屏幕上可见的 html 元素?

WKWebView 从 HTTP 请求中注入 cookie

iOS Swift5.0 WKWebView使用JS与Swift交互

iOS14,WKWebView 无法打开带有 _blank 目标的链接