使用UIWebView关于WebCore::FrameLoader::checkCompleted()在iOS12.0以后的闪退

崩溃日志是

Date/Time:           2018-11-06 23:22:48.2622 +0800
Launch Time:         2018-11-06 23:18:17.7439 +0800
OS Version:          iPhone OS 12.0.1 (16A404)
Baseband Version:    7.10.00
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000020c70f0c0
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [14822]
Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   WebCore                       	0x000000020c70f0c0 WebCore::FrameLoader::checkCompleted() + 592 (FrameLoader.cpp:832)
1   WebCore                       	0x000000020c71419c WebCore::FrameLoader::continueLoadAfterNavigationPolicy(WebCore::ResourceRequest const&, WebCore::FormState*, WebCore::ShouldContinue, WebCore::AllowNavigationToInvalidURL) + 396 (FrameLoader.cpp:3284)
2   WebCore                       	0x000000020c71419c WebCore::FrameLoader::continueLoadAfterNavigationPolicy(WebCore::ResourceRequest const&, WebCore::FormState*, WebCore::ShouldContinue, WebCore::AllowNavigationToInvalidURL) + 396 (FrameLoader.cpp:3284)
3   WebCore                       	0x000000020c71dcf4 WTF::Function&&, WebCore::ShouldContinue)>::CallableWrapper >&&, WebCore::AllowNavigationToInvalidURL, WebCore::ShouldTreatAsContinuingLoad, WTF::CompletionHandler&&)::$_9>::call(WebCore::ResourceRequest&&, WTF::WeakPtr&&, WebCore::ShouldContinue) + 48 (FrameLoader.cpp:1599)
4   WebCore                       	0x000000020c73f1a8 WTF::Function::CallableWrapper >&&, WTF::CompletionHandler&&, WebCore::ShouldContinue)>&&, WebCore::PolicyDecisionMode)::$_2>::call(WebCore::PolicyAction) + 304 (Function.h:56)
5   WebKitLegacy                  	0x000000020cfe2bdc -[WebFramePolicyListener receivedPolicyDecision:] + 72 (Function.h:56)
6   CoreFoundation                	0x0000000202e4b660 __invoking___ + 144
7   CoreFoundation                	0x0000000202d27980 -[NSInvocation invoke] + 292 (NSForwarding.m:3052)
8   CoreFoundation                	0x0000000202d28564 -[NSInvocation invokeWithTarget:] + 60 (NSForwarding.m:3123)
9   WebKitLegacy                  	0x000000020cfe2560 -[_WebSafeForwarder forwardInvocation:] + 156 (WebView.mm:5418)
10  CoreFoundation                	0x0000000202e4950c ___forwarding___ + 640 (NSForwarding.m:3263)
11  CoreFoundation                	0x0000000202e4b4bc _CF_forwarding_prep_0 + 92
12  CoreFoundation                	0x0000000202e4b660 __invoking___ + 144
13  CoreFoundation                	0x0000000202d27980 -[NSInvocation invoke] + 292 (NSForwarding.m:3052)
14  WebCore                       	0x000000020bbf37f0 HandleDelegateSource(void*) + 144 (WebCoreThread.mm:137)
15  CoreFoundation                	0x0000000202dd25b8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1980)
16  CoreFoundation                	0x0000000202dd2538 __CFRunLoopDoSource0 + 88 (CFRunLoop.c:2015)
17  CoreFoundation                	0x0000000202dd1e1c __CFRunLoopDoSources0 + 176 (CFRunLoop.c:2051)
18  CoreFoundation                	0x0000000202dccce8 __CFRunLoopRun + 1040 (CFRunLoop.c:2922)
19  CoreFoundation                	0x0000000202dcc5b8 CFRunLoopRunSpecific + 436 (CFRunLoop.c:3247)
20  GraphicsServices              	0x0000000205040584 GSEventRunModal + 100 (GSEvent.c:2245)
21  UIKitCore                     	0x000000022fc48bc8 UIApplicationMain + 212 (UIApplication.m:4341)
22  yyy                 	0x0000000100de9768 main + 352 (main.m:382)
23  libdyld.dylib                 	0x000000020288cb94 start + 4

 

这个闪退是原生调用H5的时候发生的。

交互使用了 UIWebView+TS_JavaScriptContext 

- (void)webView:(UIWebView *)webView didCreateJavaScriptContext:(JSContext *)jsContext
{
    self.jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
}

原生调用H5的方法

[self.jsContext[@"h5Method"] callWithArguments:@[value1,value2]];

上面这句话在ios12以后会发生严重闪退。

 

改成下面的调用方法可以解决

    NSString *command = [NSString stringWithFormat:@"h5Method('%@','%@');",value1,value2];
    [self.webView stringByEvaluatingJavaScriptFromString:command];

注意:value1 value2的值要加单引号,因为它们在传给js后,在js里面这两个可能是变量 而不是值。

 

 

 

 

 

你可能感兴趣的:(ios)