UIWebview阻塞主线程,同时渲染html5

时间:2012-05-30 21:14:29

标签: ios uiwebview webkit

在我的应用程序中,我使用UIWebview呈现HTML5网站。 当我选择下拉菜单时,会出现带有嵌入式UITableView的弹出窗口。 在表视图中选择条目时,JS会加载数据。 看起来Webkit正在主线程中同步加载数据。 下面提供了堆栈跟踪。 这会导致主线程挂起一段时间并冻结UI。

我遵循UIWebview指南,在主线程上创建Web视图。

同一网站在Mobile Safari上运行正常。 任何帮助表示赞赏。

#0  0x3367e004 in mach_msg_trap ()
#1  0x3367e200 in mach_msg ()
#2  0x3589a3f2 in __CFRunLoopServiceMachPort ()
#3  0x3589912a in __CFRunLoopRun ()
#4  0x3581c4a4 in CFRunLoopRunSpecific ()
#5  0x3581c36c in CFRunLoopRunInMode ()
#6  0x33edd7ca in WebCore::ResourceHandle::loadResourceSynchronously ()
#7  0x33bf5c04 in WebCore::FrameLoader::loadResourceSynchronously ()
#8  0x339ebd5a in WebCore::DocumentThreadableLoader::loadRequest ()
#9  0x339eb984 in WebCore::DocumentThreadableLoader::DocumentThreadableLoader ()
#10 0x33b65fd4 in WebCore::DocumentThreadableLoader::loadResourceSynchronously ()
#11 0x33f4880a in WebCore::ThreadableLoader::loadResourceSynchronously ()
#12 0x339eb5bc in WebCore::XMLHttpRequest::createRequest ()
#13 0x339eb35a in WebCore::XMLHttpRequest::send ()
#14 0x339eaeea in WebCore::JSXMLHttpRequest::send ()
#15 0x339ead98 in WebCore::jsXMLHttpRequestPrototypeFunctionSend ()
#16 0x356de598 in JSC::Interpreter::privateExecute ()
#17 0x3575d0ec in JSC::Interpreter::executeCall ()
#18 0x3575ccd0 in JSC::call ()
#19 0x339d5f0e in WebCore::JSEventListener::handleEvent ()
#20 0x339d5bd2 in WebCore::EventTarget::fireEventListeners ()
#21 0x338dc7c6 in WebCore::EventTarget::fireEventListeners ()
#22 0x338e2d38 in WebCore::Node::handleLocalEvents ()
#23 0x338e2588 in WebCore::EventDispatcher::dispatchEvent ()
#24 0x338e233a in WebCore::EventDispatchMediator::dispatchEvent ()
#25 0x338e230e in WebCore::EventDispatcher::dispatchEvent ()
#26 0x338e2266 in WebCore::Node::dispatchEvent ()
#27 0x33e757f4 in WebCore::Node::dispatchChangeEvent ()
#28 0x33c278aa in WebCore::HTMLFormControlElement::dispatchFormControlChangeEvent ()
#29 0x33eeb7a8 in WebCore::SelectElement::menuListOnChange ()
#30 0x33eeb7be in WebCore::SelectElement::dispatchBlurEvent ()
#31 0x33c35670 in WebCore::HTMLSelectElement::dispatchBlurEvent ()
#32 0x338e1a4e in WebCore::Document::setFocusedNode ()
#33 0x338e1788 in WebCore::FocusController::setFocusedNode ()
#34 0x33bdfdfe in WebCore::Element::blur ()
#35 0x33b802d0 in -[DOMElement blur] ()
#36 0x358c97e4 in __invoking___ ()
#37 0x358247b0 in -[NSInvocation invoke] ()
#38 0x358243ce in -[NSInvocation invokeWithTarget:] ()
#39 0x306824c0 in -[UIThreadSafeNode forwardInvocation:] ()
#40 0x358c8a82 in ___forwarding___ ()
#41 0x35823650 in __forwarding_prep_0___ ()
#42 0x30511acc in -[UIWebBrowserView resignFirstResponder] ()
#43 0x305e6658 in -[UIWebSelectTableViewController tableView:didSelectRowAtIndexPath:] ()
#44 0x3047bae4 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] ()
#45 0x304f57aa in -[UITableView _userSelectRowAtPendingSelectionIndexPath:] ()
#46 0x346ad932 in __NSFireDelayedPerform ()
#47 0x3589aa32 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#48 0x3589a698 in __CFRunLoopDoTimer ()
#49 0x3589926e in __CFRunLoopRun ()
#50 0x3581c4a4 in CFRunLoopRunSpecific ()
#51 0x3581c36c in CFRunLoopRunInMode ()
#52 0x3559b438 in GSEventRunModal ()
#53 0x303f7e7c in UIApplicationMain ()

1 个答案:

答案 0 :(得分:0)

您是否可以更具体地了解如何调用请求并将数据传递到UIWebView?

例如:您是否设置了UIWebViewDelegate来控制willStartLoading和didFinishLoading? 您是否已将NSURLRequest设置为同步或异步?

通常,委托在单独的线程上加载UIWebView,以便不阻止main。 我假设您需要对某些参数进行更多工作才能使其正确。