UIKit崩溃与WebView有关

时间:2014-11-28 12:08:19

标签: ios objective-c uiwebview

我在UIKit中发生了一次随机崩溃,已经发生了几次。

它与EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000d

崩溃
Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x30e08f46 objc_msgSend + 5
1  UIKit                          0x26d1790d -[_UIWebViewScrollViewDelegateForwarder forwardInvocation:] + 140
2  CoreFoundation                 0x23654def ___forwarding___ + 354
3  CoreFoundation                 0x23586df8 _CF_forwarding_prep_0 + 24
4  UIKit                          0x26b5a6fd -[UIScrollView _getDelegateZoomView] + 84
5  UIKit                          0x26b5a635 -[UIScrollView _zoomScaleFromPresentationLayer:] + 24
6  UIKit                          0x26b5a5ed -[UIWebDocumentView _zoomedDocumentScale] + 64
7  UIKit                          0x26b5a13d -[UIWebDocumentView _layoutRectForFixedPositionObjects] + 104
8  UIKit                          0x26b59f97 -[UIWebDocumentView _updateFixedPositionedObjectsLayoutRectUsingWebThread:synchronize:] + 38
9  UIKit                          0x26b5c3e5 -[UIWebDocumentView _updateFixedPositioningObjectsLayoutAfterScroll] + 28
10 UIKit                          0x26b5c3c1 -[UIWebBrowserView _updateFixedPositioningObjectsLayoutAfterScroll] + 56
11 CoreFoundation                 0x2360a281 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
12 CoreFoundation                 0x2356652d _CFXNotificationPost + 1784
13 Foundation                     0x24296189 -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
14 UIKit                          0x27171dd7 -[UIInputWindowController postEndNotifications:withInfo:] + 554
15 UIKit                          0x271732ed __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke595 + 368
16 UIKit                          0x26b44b05 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 308
17 UIKit                          0x26b4471d -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 184
18 UIKit                          0x26b4462f -[UIViewAnimationState animationDidStop:finished:] + 66
19 QuartzCore                     0x2653d2d9 CA::Layer::run_animation_callbacks(void*) + 236
20 libdispatch.dylib              0x3135c7a7 _dispatch_client_callout + 22
21 libdispatch.dylib              0x3135ffa3 _dispatch_main_queue_callback_4CF + 718
22 CoreFoundation                 0x236179d1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
23 CoreFoundation                 0x236160d1 __CFRunLoopRun + 1512
24 CoreFoundation                 0x23564211 CFRunLoopRunSpecific + 476
25 CoreFoundation                 0x23564023 CFRunLoopRunInMode + 106
26 GraphicsServices               0x2a95d0a9 GSEventRunModal + 136
27 UIKit                          0x26b701d1 UIApplicationMain + 1440
28 MY_PROJECT                     0x000842cf main (main.m:16)

看起来它与UIWebView有关,但我不知道发生了什么 - 任何帮助都表示赞赏 这次事故似乎在中国众所周知......

2 个答案:

答案 0 :(得分:0)

正如@ NilsHolgerson所提到的,我遇到了一些通知问题。 最可能的原因是没有正确删除的通知,并且确实保留了一个分离的ViewController:

   [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
                [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
                ...

解决方案如下:

__weak typeof(self) weakself = self;
__block NSObject *reference = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
                [[NSNotificationCenter defaultCenter] removeObserver:reference];
                ...

答案 1 :(得分:0)

这个问题的深层原因是:当webView做一些动画时,已经发布了Container ViewController。

因此,直接解决方案在ViewControllers dealloc 时将webView的委托设置为nil。

当然如果你适当地发布VC,@ dogsgod也是一个解决方案。

相关问题