Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios cfNotificationCenterRemoveeVeryoObserver不删除观察者_Ios_Objective C - Fatal编程技术网

Ios cfNotificationCenterRemoveeVeryoObserver不删除观察者

Ios cfNotificationCenterRemoveeVeryoObserver不删除观察者,ios,objective-c,Ios,Objective C,我正在使用CFNotificationCenterAddObserver()函数注册通知,如下所示 CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, ringerSwitched, CFSTR

我正在使用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");

谢谢你的回复。我找到了解决办法。正如你提到的,它不是@“观察者标识符”,而是一个c字符串。i、 e“观察员标识符”谢谢您的提及。