當一個對象添加了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