我正在使用CFNotificationCenterAddObserver()函数注册通知,如下所示
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);
答案 0 :(得分:1)
为观察者提供标识符。
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
"observer identifier",
ringerSwitched,
CFSTR("com.apple.springboard.ringerstate"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), @"observer identifier");