How to know where crash for postNotificationName:object:userInfo

三世轮回 提交于 2019-12-05 16:30:57

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.

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.

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

Maybe userInfo is has nil value....

[[NSNotificationCenter defaultCenter] postNotificationName:SayLoggedInNotification object:wSelf userInfo:@{@"from": wSelf.from}];
# wSelf.form is nil
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!