gpt4 book ai didi

iOS WKWebView JavaScriptCore WTFCrash

转载 作者:行者123 更新时间:2023-12-01 15:23:31 32 4
gpt4 key购买 nike

我在我们的应用程序上添加了一个 webview 实例。但是,有时会发生崩溃。
调用堆栈上的崩溃称为 JavaScriptCore WTFCrash。

Crashed: com.apple.main-thread
0 JavaScriptCore 0x26062a22 WTFCrash + 53
1 JavaScriptCore 0x260629cd WTFPrintBacktrace + 128
2 WebKit 0x29a2ab95 WTF::HashTable<unsigned long long, WTF::KeyValuePair<unsigned long long, WTF::RefPtr<WebKit::CallbackBase> >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<unsigned long long, WTF::RefPtr<WebKit::CallbackBase> > >, WTF::IntHash<unsigned long long>, WTF::HashMap<unsigned long long, WTF::RefPtr<WebKit::CallbackBase>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<WTF::RefPtr<WebKit::CallbackBase> > >::KeyValuePairTraits, WTF::HashTraits<unsigned long long> >::begin() const + 30
3 WebKit 0x29a2ab4d WTF::Vector<WTF::RefPtr<WebKit::CallbackBase>, 0ul, WTF::CrashOnOverflow, 16ul>::reserveCapacity(unsigned long) + 24
4 WebKit 0x29a2aaa5 WTF::Vector<WTF::RefPtr<WebKit::CallbackBase>, 0ul, WTF::CrashOnOverflow, 16ul>::resize(unsigned long) + 44
5 WebKit 0x29a2a955 void WebKit::invalidateCallbackMap<WTF::RefPtr<WebKit::CallbackBase> >(WTF::HashMap<unsigned long long, WTF::RefPtr<WebKit::CallbackBase>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<WTF::RefPtr<WebKit::CallbackBase> > >&, WebKit::CallbackBase::Error) + 104
6 WebKit 0x29ad18b1 WebKit::WebPageProxy::resetState(WebKit::WebPageProxy::ResetStateReason) + 456
7 WebKit 0x29ad0897 WebKit::WebPageProxy::close() + 78
8 WebKit 0x29b8496d -[WKWebView dealloc] + 120
9 libobjc.A.dylib 0x223c13a9 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 388
10 CoreFoundation 0x22b1af89 _CFAutoreleasePoolPop + 16
11 CoreFoundation 0x22b2a251 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 140
12 UIKit 0x2719f2ed -[UIViewController _setViewAppearState:isAnimating:] + 1088
13 UIKit 0x272152d1 -[UIViewController __viewDidDisappear:] + 172
14 UIKit 0x2719f6d3 -[UIViewController _endAppearanceTransition:] + 258
15 UIKit 0x2725b6fb -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 886
16 UIKit 0x2733680f __49-[UINavigationController _startCustomTransition:]_block_invoke + 210
17 UIKit 0x272b4157 -[_UIViewControllerTransitionContext completeTransition:] + 90
18 UIKit 0x27418c7b __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke95 + 682
19 UIKit 0x271c1ba5 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 540
20 UIKit 0x271c1685 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 204
21 UIKit 0x271c157f -[UIViewAnimationState animationDidStop:finished:] + 78
22 QuartzCore 0x25221689 CA::Layer::run_animation_callbacks(void*) + 252
23 libdispatch.dylib 0x2277980f _dispatch_client_callout + 22
24 libdispatch.dylib 0x22787ba9 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1524
25 CoreFoundation 0x22bcdb6d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
26 CoreFoundation 0x22bcc067 __CFRunLoopRun + 1574
27 CoreFoundation 0x22b1b229 CFRunLoopRunSpecific + 520
28 CoreFoundation 0x22b1b015 CFRunLoopRunInMode + 108
29 GraphicsServices 0x2410bac9 GSEventRunModal + 160
30 UIKit 0x271ef189 UIApplicationMain + 144
31 App 0x12d600 main (AppDelegate.swift:14)
32 libdispatch.dylib 0x227c3873 (Missing)

有没有人遇到过类似的这个问题?

最佳答案

您的代码有两个问题:
- stringByEvaluatingJavaScriptFromString : 返回一个自动释放的 NSString。因此,您不需要使用 stringWithFormat: .
- 您的代码也没有有效的格式。

pageText = [NSString stringWithFormat:@"%@", [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];

但是,将更正格式错误,因为您正在分配 pageText由于 autorelease,您稍后会面临崩溃的风险.

以下是所有必要的。注意:我假设 Javascript 是有效的......
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[pageText release], pageText = nil;

pageText = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"] retain];

if (!pageText)
// innerHTML was empty
pageText = [[webView stringByEvaluatingJavaScriptFromString:@"document.body"] retain];
}

请注意,添加了保留是因为您正在分配 pageText ivar 而不是使用 setter。确保添加 [pageText release];在您的 dealloc 中以防止泄漏。尝试访问 pageText 时要非常小心在您的代码中的其他地方,因为它仍然可能为零。保持防守。

关于iOS WKWebView JavaScriptCore WTFCrash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40125218/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com