降低崩溃率之--通知造成NSNotification crash

当一个对象添加了notification之后,如果dealloc的时候,仍然持有notification,就会出现NSNotification类型的crash。NSNotification类型的crash多产生于程序员写代码时候犯疏忽,在NSNotificationCenter添加一个对象为observer之后,忘记了在对象dealloc的时候移除它。所幸的是,苹果在iOS9之后专门针对于这种情况做了处理,所以在iOS9之后,即使开发者没有移除observer,Notification crash也不会再产生了。不过针对于iOS9之前的用户,我们还是有必要做一下NSNotification Crash的防护的。


image.png

代码详见GitHub
https://github.com/Darren-liang/NotificationCrash

你可能感兴趣的:(降低崩溃率之--通知造成NSNotification crash)