How to know where crash for postNotificationName:object:userInfo

早过忘川 提交于 2019-12-22 08:25:48

问题


Is there some method to know crash reason in Xcode 4.6?

The crash stack is :
Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0xd9f2c061
Crashed Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib                     0x3a74f5aa objc_msgSend + 10
1   Foundation                          0x33157599 -[NSNotificationCenter postNotificationName:object:userInfo:] + 73
2   UIKit                               0x347830cd -[UIApplication _handleApplicationSuspend:eventInfo:] + 733
3   UIKit                               0x346f91e7 -[UIApplication handleEvent:withNewEvent:] + 2459
4   UIKit                               0x346f86cd -[UIApplication sendEvent:] + 73
5   UIKit                               0x346f811b _UIApplicationHandleEvent + 6155
6   GraphicsServices                    0x363ee5a3 _PurpleEventCallback + 591

回答1:


When you add an observer to the notification centre you have to remove it when the object is being dealloced/destroyed. Otherwise Notification Centre would send the notification to the destroyed object resulting in crash.

1 - check if you properly handle the removing from notification centre. (typically you do this on dealloc method)

2 - If step 1 doesn't help, profile your application with instruments & zombies. it would point out which object is destroyed but still receiving messages.




回答2:


Almost certainly an object registered with the notification centre to receive that notification and then failed to deregister before deallocation.

The easiest way to catch the problem would be to enable NSZombies — see e.g. this tutorial. If you run with zombies enabled then objects that should have been deallocated remain in memory but raise an exception if anyone attempts to call them. So you can figure out exactly what type of object the notification centre is attempting to call and therefore which object is probably making the mistake.

Given the name of the origin of the notification — _handleApplicationSuspend:eventInfo: — you might also want to have a quick check of anyone registering for UIApplicationWillResignActiveNotification, UIApplicationDidEnterBackgroundNotification and the others related to application suspension.




回答3:


Might be an useful information that it appears to crash only on ios7, as my project ran perfectly on ios6.




回答4:


Maybe userInfo is has nil value....

[[NSNotificationCenter defaultCenter] postNotificationName:SayLoggedInNotification object:wSelf userInfo:@{@"from": wSelf.from}];
# wSelf.form is nil


来源:https://stackoverflow.com/questions/18523927/how-to-know-where-crash-for-postnotificationnameobjectuserinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!