UIWebView崩溃从HTML加载链接

时间:2013-05-14 06:30:14

标签: string jquery-mobile uiwebview crash

如果我在包含外部链接的UIWebView中调用loadHTMLString,那么再次尝试loadHTMLString崩溃。

HTML按如下方式加载:

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"help" withExtension:@"html"];
    NSString *text = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

    [[self webView] loadHTMLString:text baseURL:nil];

help.html可以包含以下链接:

Example

如果点击该链接,则会加载该页面。但是我在导航栏上有一个“Home”按钮,它再次调用上面的代码(loadHTMLString),这会使应用程序崩溃。

在查看外部链接后,有什么方法可以“欺骗”UIWebView再次加载HTML字符串?

参考文献: UIWebView won't goBack after loading HTML in iOS

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'

#0  0x906b29c6 in __pthread_kill ()
#1  0x9ca6ff78 in pthread_kill ()
#2  0x0399957b in abort ()
#3  0x03b19f7b in abort_message ()
#4  0x03b17a25 in default_terminate() ()
#5  0x035620c1 in _objc_terminate() ()
#6  0x03b17a65 in safe_handler_caller(void (*)()) ()
#7  0x03b17acd in std::terminate() ()
#8  0x03b18bc2 in __cxa_throw ()
#9  0x03561f89 in objc_exception_throw ()
#10 0x03fd50de in -[__NSDictionaryM setObject:forKey:] ()
#11 0x03d485ce in -[WebHistoryPrivate visitedURL:withTitle:increaseVisitCount:] ()
#12 0x03d4a693 in -[WebHistory(WebInternal) _visitedURL:withTitle:method:wasFailure:increaseVisitCount:] ()
#13 0x03d394b5 in WebFrameLoaderClient::updateGlobalHistory() ()
#14 0x04db0747 in WebCore::HistoryController::replaceState(WTF::PassRefPtr<WebCore::SerializedScriptValue>, WTF::String const&, WTF::String const&) ()
#15 0x04dad610 in WebCore::History::stateObjectAdded(WTF::PassRefPtr<WebCore::SerializedScriptValue>, WTF::String const&, WTF::String const&, WebCore::History::StateObjectType, int&) ()
#16 0x0508041a in WebCore::JSHistory::replaceState(JSC::ExecState*) ()
#17 0x0507ec49 in WebCore::jsHistoryPrototypeFunctionReplaceState(JSC::ExecState*) ()
#18 0x0d892daf in 0x0d892daf ()
#19 0x08052e11 in JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) ()
#20 0x07fabfc3 in JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) ()
#21 0x04f91d34 in WebCore::JSMainThreadExecState::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) ()
#22 0x05064d15 in WebCore::JSEventListener::handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) ()
#23 0x04ce9eac in WebCore::EventTarget::fireEventListeners(WebCore::Event*, WebCore::EventTargetData*, WTF::Vector<WebCore::RegisteredEventListener, 1ul>&) ()
#24 0x04ce9c76 in WebCore::EventTarget::fireEventListeners(WebCore::Event*) ()
#25 0x05333ce9 in WebCore::Node::handleLocalEvents(WebCore::Event*) ()
#26 0x04cd0419 in WebCore::EventDispatcher::dispatchEvent(WTF::PassRefPtr<WebCore::Event>) ()
#27 0x04cd16da in WebCore::EventDispatchMediator::dispatchEvent(WebCore::EventDispatcher*) const ()
#28 0x04ccf72e in WebCore::EventDispatcher::dispatchEvent(WebCore::Node*, WTF::PassRefPtr<WebCore::EventDispatchMediator>) ()
#29 0x05333eaa in WebCore::Node::dispatchEvent(WTF::PassRefPtr<WebCore::Event>) ()
#30 0x04bf85ad in WebCore::Document::finishedParsing() ()
#31 0x04e570ad in WebCore::HTMLTreeBuilder::finished() ()
#32 0x04dd4a9b in WebCore::HTMLDocumentParser::prepareToStopParsing() ()
#33 0x04c16a14 in WebCore::DocumentWriter::end() ()
#34 0x04c092a3 in WebCore::DocumentLoader::finishedLoading() ()
#35 0x052f6c22 in WebCore::MainResourceLoader::didFinishLoading(double) ()
#36 0x052f5c58 in WebCore::MainResourceLoader::continueAfterContentPolicy(WebCore::PolicyAction, WebCore::ResourceResponse const&) ()
#37 0x052f650e in WebCore::MainResourceLoader::didReceiveResponse(WebCore::ResourceResponse const&) ()
#38 0x052f4a58 in WebCore::MainResourceLoader::handleDataLoadNow(WebCore::Timer<WebCore::MainResourceLoader>*) ()
#39 0x052f8016 in WebCore::Timer<WebCore::MainResourceLoader>::fired() ()
#40 0x056e415c in WebCore::ThreadTimers::sharedTimerFiredInternal() ()
#41 0x056e4036 in WebCore::ThreadTimers::sharedTimerFired() ()
#42 0x05531c50 in WebCore::timerFired(__CFRunLoopTimer*, void*) ()
#43 0x03f11376 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#44 0x03f10e06 in __CFRunLoopDoTimer ()
#45 0x03ef8a82 in __CFRunLoopRun ()
#46 0x03ef7f44 in CFRunLoopRunSpecific ()
#47 0x03ef7e1b in CFRunLoopRunInMode ()
#48 0x05723c50 in RunWebThread(void*) ()
#49 0x9ca6ded9 in _pthread_start ()

1 个答案:

答案 0 :(得分:0)

好吧,它似乎是UIWebview上的一个错误。即使没有内容或HTML错误,UIwebview也不会崩溃。发现错误