最近聽云上監(jiān)聽到一個crash,內容如下:
An instance 0x11c9d7400 of class WKWebView was deallocated while
key value observers were still registered with it.
Current observation info:
<NSKeyValueObservationInfo 0x172a3b600>
( <NSKeyValueObservance 0x170e498d0:
Observer: 0x177231b20, Key path: load)
看一下崩潰路徑旧蛾,就是用戶進入webView,然后點擊返回按鈕返回毯盈,就直接crash掉了。
但是我看到相應的VC中只有兩個kvo搂赋,一個title的益缠,一個estimatedProgress,根本就沒有一個load相關的脑奠。然后我又搜遍了所有的webview相關的幅慌,也沒有發(fā)現有一個load的監(jiān)聽。
后來找到了一種方法胰伍,可以打印webView觀察者相關的信息
id info = self.webView.observationInfo;
id info1 = [info valueForKey:@"_observances"];
id info2 = [info1 valueForKey:@"_property"];
id info3 = [info2 valueForKey:@"_keyPath"];
NSLog(@"====== 0 %@",info);
NSLog(@"====== 1 %@",info1);
NSLog(@"====== 2 %@",info2);
NSLog(@"====== 3 %@",info3);
打印出來結果如下:
2021-06-02 12:17:39.440592+0800 shansong[13307:3766327] ====== 0 <NSKeyValueObservationInfo 0x2807fa5a0> (
<NSKeyValueObservance 0x281f0a070: Observer: 0x2807f01e0, Key path: loading, Options: <New: YES, Old: NO, Prior: NO> Context: 0x10b085000, Property: 0x281f09f20>
<NSKeyValueObservance 0x281f0a190: Observer: 0x107d18240, Key path: title, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x281f0a160>
<NSKeyValueObservance 0x281f0a2b0: Observer: 0x107d18240, Key path: estimatedProgress, Options: <New: NO, Old: NO, Prior: NO> Context: 0x105979f30, Property: 0x281f0a220>
)
2021-06-02 12:17:39.440724+0800 shansong[13307:3766327] ====== 1 (
"<NSKeyValueObservance 0x281f0a070: Observer: 0x2807f01e0, Key path: loading, Options: <New: YES, Old: NO, Prior: NO> Context: 0x10b085000, Property: 0x281f09f20>",
"<NSKeyValueObservance 0x281f0a190: Observer: 0x107d18240, Key path: title, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x281f0a160>",
"<NSKeyValueObservance 0x281f0a2b0: Observer: 0x107d18240, Key path: estimatedProgress, Options: <New: NO, Old: NO, Prior: NO> Context: 0x105979f30, Property: 0x281f0a220>"
)
2021-06-02 12:17:39.440858+0800 shansong[13307:3766327] ====== 2 (
"<NSKeyValueUnnestedProperty: Container class: DWKWebView, Key: loading, isa for autonotifying: NSKVONotifying_DWKWebView, Key paths of directly and indirectly affecting properties: none>",
"<NSKeyValueUnnestedProperty: Container class: DWKWebView, Key: title, isa for autonotifying: NSKVONotifying_DWKWebView, Key paths of directly and indirectly affecting properties: none>",
"<NSKeyValueUnnestedProperty: Container class: DWKWebView, Key: estimatedProgress, isa for autonotifying: NSKVONotifying_DWKWebView, Key paths of directly and indirectly affecting properties: none>"
)
2021-06-02 12:17:39.440908+0800 shansong[13307:3766327] ====== 3 (
loading,
title,
estimatedProgress
)
然后發(fā)現這個loading的observer和我自己添加的兩個不一樣喇辽,于是查了下這個loading的class,
(lldb) p ((id)0x2807f01e0)->isa
(Class) $0 = NBSWKWebViewObserver
發(fā)現這個罪魁禍首吠式,NBSWKWebViewObserver,NBS相關的就是聽云的特占,后來我把項目的聽云sdk刪掉再運行就沒有這個可惡的loading了。
后面是目,就是如何和聽云相關的溝通了。