关键词: WKWebView SIGSEGV(11) WebKit::LegacyCustomProtocolManagerProxy::stopLoading(unsigned long long) WKProcessPool
在QA测试疯狂把玩App时,突然出现了crash问题,而且还是一个概率非常小的偶发crash。吓得我立马跑到bugly上查看crash记录。在通过符号表转换后,我得到了以下crash时的堆栈信息。
代码语言:javascript复制0 WebKit WebKit::LegacyCustomProtocolManagerProxy::stopLoading(unsigned long long) 20
1 CFNetwork ___65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke 60
2 CFNetwork -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] 196
3 CFNetwork -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] 56
4 CFNetwork ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke 100
5 CFNetwork ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 108
6 libdispatch.dylib __dispatch_client_callout 16
7 libdispatch.dylib __dispatch_block_invoke_direct$VARIANT$armv81 216
8 CFNetwork RunloopBlockContext::_invoke_block(void const*, void*) 36
9 CoreFoundation CFArrayApplyFunction 80
10 CFNetwork RunloopBlockContext::perform() 128
11 CFNetwork MultiplexerSource::perform() 312
12 CFNetwork MultiplexerSource::_perform(void*) 60
13 CoreFoundation ___CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ 24
14 CoreFoundation ___CFRunLoopDoSource0 88
15 CoreFoundation ___CFRunLoopDoSources0 176
16 CoreFoundation ___CFRunLoopRun 1004
17 CoreFoundation CFRunLoopRunSpecific 436
18 GraphicsServices GSEventRunModal 104
19 UIKitCore UIApplicationMain 212
20 gymbo 0x0000000104f50000 717816
21 libdyld.dylib _start 4
触发场景: 加载WKWebView的ViewController被释放,但WKWebView内容还在加载中,即使在VC的 dealloc(swift版本的是 deinit 方法)中设置webView stoploading以及WKWebView UIDelegate和navigationDelegate设置为nil,也会偶发该崩溃。
解决方案: WKWebView中的WKProcessPool类,设置成单例 代码:swift版 声明WKProcessPool为单例
代码语言:javascript复制// MARK: - 扩展WKProcessPool,使其变成单例,所有WKWebView共享Cookie数据
extension WKProcessPool {
static var SharedProcessPool: WKProcessPool = {
var sharePool = WKProcessPool()
return sharePool
}()
class func sharedProcessPool() -> WKProcessPool {
return SharedProcessPool
}
}
在WKWebView初始化时,配置processPool
代码语言:javascript复制 let configuration = WKWebViewConfiguration()
configuration.processPool = WKProcessPool.sharedProcessPool()
let webView = WKWebView(frame: UIScreen.main.bounds, configuration: configuration)
后面会说明查找分析问题过程以及其中原理
bugly符号表解析后的出错堆栈截图
bugly自定义跟踪日志截图
方案有效的原因: WKProcessPool类的作用,以及崩溃触发的根本原因,还在研究中~后续会补充