Ios cfNotificationCenterRemoveeVeryoObserver不删除观察者
我正在使用CFNotificationCenterAddObserver()函数注册通知,如下所示Ios cfNotificationCenterRemoveeVeryoObserver不删除观察者,ios,objective-c,Ios,Objective C,我正在使用CFNotificationCenterAddObserver()函数注册通知,如下所示 CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, ringerSwitched, CFSTR
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
ringerSwitched,
CFSTR("com.apple.springboard.ringerstate"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
稍后,我将通过CFNotificationCenterRemoveEveryObserver()函数删除它,如下所示,但仍会调用回调方法
CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL);
我还使用了CFNotificationCenterRemoveObserver()函数取消注册,但没有任何用处
CFNotificationCenterRemoveObserver (CFNotificationCenterGetDarwinNotifyCenter(), NULL, CFSTR("com.apple.springboard.ringerstate"), NULL);
为观察者提供标识符
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
"observer identifier",
ringerSwitched,
CFSTR("com.apple.springboard.ringerstate"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), @"observer identifier");
谢谢你的回复。我找到了解决办法。正如你提到的,它不是@“观察者标识符”,而是一个c字符串。i、 e“观察员标识符”谢谢您的提及。