iOS 崩溃日志分析经验 -- UINavigationDelegate

上架的App会需要去定期观察有没有发生Crash,入口是Windows-organizer,点击archives右侧的Crashes,然后选择自己发布版本的包,就可以看到崩溃log日志

对于崩溃的log,有些可以直接分析出来原因,有些无法直接看出来,就需要自己逐步来分析。

比如说:

(1)崩溃的日志,之前的版本是否存在,如果不存在,可以使用Kaleidoscope对比两个version的代码区别

(2)崩溃的日志出现在哪些机型,哪些版本,会存在你的方法在iOS 10下可以用,但是在iOS8.4可以用,但是iOS 8.1可以用

最近遇到一个崩溃,就是一个比较纠结的问题,无法从crash的log信息里面查出原因,log日志如下:

xception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000010
Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   libobjc.A.dylib               	0x00000001923d7bd0 objc_msgSend + 16 (objc-msg-arm64.s:96)
1   UIKit                         	0x0000000186515b94 -[UINavigationController viewWillAppear:] + 468 (UINavigationController.m:2916)
2   UIKit                         	0x000000018647ba58 -[UIViewController _setViewAppearState:isAnimating:] + 512 (UIViewController.m:3462)
3   UIKit                         	0x000000018659e47c -[UITabBarController viewWillAppear:] + 240 (UITabBarController.m:558)
4   LVCloudCamera                 	0x0000000100205628 -[LVTabBarMenuViewController viewWillAppear:] + 88 (LVTabBarMenuViewController.m:470)
5   UIKit                         	0x000000018647ba58 -[UIViewController _setViewAppearState:isAnimating:] + 512 (UIViewController.m:3462)
6   UIKit                         	0x000000018646c2f0 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 600 (UIView.m:5780)
7   UIKit                         	0x000000018646b7c0 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 488 (UIView.m:8825)
8   LVCloudCamera                 	0x00000001001845a4 -[DDMenuController setRightRootViewController:] + 332 (DDMenuController.m:800)
9   LVCloudCamera                 	0x0000000100183a34 __39-[DDMenuController showLeftController:]_block_invoke + 400 (DDMenuController.m:658)
10  UIKit                         	0x000000018649909c +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 504 (UIView.m:7706)
11  UIKit                         	0x00000001865e089c +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:completion:] + 60 (UIView.m:7762)
12  LVCloudCamera                 	0x0000000100183848 -[DDMenuController showLeftController:] + 996 (DDMenuController.m:647)
13  LVCloudCamera                 	0x0000000100185360 -[DDMenuController showLeft:] + 476 (DDMenuController.m:980)
14  UIKit                         	0x0000000186498d30 -[UIApplication sendAction:to:from:forEvent:] + 92 (UIApplication.m:3337)
15  UIKit                         	0x0000000186481e44 -[UIControl _sendActionsForEvents:withEvent:] + 608 (UIControl.m:644)
16  UIKit                         	0x00000001864986cc -[UIControl touchesEnded:withEvent:] + 588 (UIControl.m:414)
17  UIKit                         	0x0000000186498358 -[UIWindow _sendTouchesForEvent:] + 696 (UIWindow.m:1877)
18  UIKit                         	0x00000001864918ac -[UIWindow sendEvent:] + 680 (UIWindow.m:1977)
19  UIKit                         	0x0000000186464fa4 -[UIApplication sendEvent:] + 260 (UIApplication.m:9838)
20  UIKit                         	0x0000000186703f54 _UIApplicationHandleEventFromQueueEvent + 14988 (UIApplication.m:8197)
21  UIKit                         	0x000000018646350c _UIApplicationHandleEventQueue + 1612 (UIApplication.m:7560)
22  CoreFoundation                	0x0000000181c6a9e8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20 (CFRunLoop.c:1763)
23  CoreFoundation                	0x0000000181c69c8c __CFRunLoopDoSources0 + 260 (CFRunLoop.c:1809)
24  CoreFoundation                	0x0000000181c67d3c __CFRunLoopRun + 708 (CFRunLoop.c:2526)
25  CoreFoundation                	0x0000000181b950a0 CFRunLoopRunSpecific + 392 (CFRunLoop.c:2795)
26  GraphicsServices              	0x000000018ad3f5a0 GSEventRunModal + 164 (GSEvent.c:2245)
27  UIKit                         	0x00000001864ca3bc UIApplicationMain + 1484 (UIApplication.m:2926)
28  LVCloudCamera                 	0x0000000100211f24 main + 84 (main.m:19)
29  libdyld.dylib                 	0x0000000192a32a04 tlv_get_addr + 176 (start_glue.s:78)

Thread 0 name:
Thread 0 Crashed:
0   libobjc.A.dylib               	0x000000019534bbd0 objc_msgSend + 16 (objc-msg-arm64.s:96)
1   UIKit                         	0x00000001886f735c -[UINavigationController _startCustomTransition:] + 968 (UINavigationController.m:1443)
2   UIKit                         	0x0000000188609eec -[UINavigationController _startDeferredTransitionIfNeeded:] + 464 (UINavigationController.m:4412)
3   UIKit                         	0x0000000188609cb8 -[UINavigationController __viewWillLayoutSubviews] + 52 (UINavigationController.m:4625)
4   UIKit                         	0x0000000188609c38 -[UILayoutContainerView layoutSubviews] + 196 (UILayoutContainerView.m:77)
5   UIKit                         	0x000000018855175c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 576 (UIView.m:10070)
6   QuartzCore                    	0x0000000187e99e18 -[CALayer layoutSublayers] + 148 (CALayer.mm:8656)
7   QuartzCore                    	0x0000000187e94880 CA::Layer::layout_if_needed(CA::Transaction*) + 316 (CALayer.mm:8536)
8   QuartzCore                    	0x0000000187e94724 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 28 (CALayer.mm:2383)
9   QuartzCore                    	0x0000000187e93eb8 CA::Context::commit_transaction(CA::Transaction*) + 272 (CAContextInternal.cpp:1566)
10  QuartzCore                    	0x0000000187e93c38 CA::Transaction::commit() + 524 (CATransactionInternal.cpp:418)
11  UIKit                         	0x00000001885536f0 _UIApplicationHandleEventQueue + 1796 (UIApplication.m:7802)
12  CoreFoundation                	0x0000000183acc23c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20 (CFRunLoop.c:1763)
13  CoreFoundation                	0x0000000183acb4e0 __CFRunLoopDoSources0 + 260 (CFRunLoop.c:1809)
14  CoreFoundation                	0x0000000183ac9590 __CFRunLoopRun + 708 (CFRunLoop.c:2526)
15  CoreFoundation                	0x00000001839f52d0 CFRunLoopRunSpecific + 392 (CFRunLoop.c:2795)
16  GraphicsServices              	0x000000018d20b6f8 GSEventRunModal + 164 (GSEvent.c:2245)
17  UIKit                         	0x00000001885bafa8 UIApplicationMain + 1484 (UIApplication.m:3039)
18  LVCloudCamera                 	0x00000001001edf24 main + 84 (main.m:19)
19  libdyld.dylib                 	0x00000001959b6a04 tlv_get_addr + 176 (threadLocalHelpers.s:279)

最后通过对比代码发现有一个ViewController中多使用了一个代理UINavigationDelegate

#pragma mark - UINavigationControllerDelegate
- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

这个方法,实在 是iOS8.3及以下会有这个问题,iOS9及以上就没有这个问题了,因为delegate改为weak类型的了

所以,如果你的项目支持iOS8 和 iOS 9稳妥的解决办法是

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.delegate = nil;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值