我正在使用 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);
为您的观察者提供标识符。
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
"observer identifier",
ringerSwitched,
CFSTR("com.apple.springboard.ringerstate"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), @"observer identifier");
关于ios - CFNotificationCenterRemoveEveryObserver 不删除观察者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30863121/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |