由於在作一個即時通信APP,用到了語音通話等,在以前NSNotificationCenter一直能夠接收到消息,升級xcode11.1的時候,應該是蘋果對NSNotificationCenter進行了安全措施,以前是放在了viewDidLoad裏面 後來查找資料正確的姿式應該是xcode
-(void)viewWillAppear:(BOOL)animated {安全
[super viewWillAppear:animated];app
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test) name:@"test" object:nil]; }code
-(void)viewWillDisappear:(BOOL)animated {server
[super viewWillDisappear:animated];rem
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"test" object:nil]; }io
還有就是項目中可能還有[[NSNotificationCenter defaultCenter] removeObserver:self]; 可能還沒收到通知以前本身移除了,因此要細心哦test
解決了個人問題,可是大多數人應該和我同樣,放在了viewDidLoad裏面,移除用的dealloc裏,若是這個方法解決不了,就用上述觀點。object