2

I am using CFNotificationCenterAddObserver() function to register a notification as below

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
                                NULL,
                                ringerSwitched,
                                CFSTR("com.apple.springboard.ringerstate"),
                                NULL,
                                CFNotificationSuspensionBehaviorDeliverImmediately);

Later at some point I am removing it via CFNotificationCenterRemoveEveryObserver() function as below but call back method is still getting called.

CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL);

I also used CFNotificationCenterRemoveObserver() function to unregister but no use.

CFNotificationCenterRemoveObserver (CFNotificationCenterGetDarwinNotifyCenter(), NULL, CFSTR("com.apple.springboard.ringerstate"), NULL);
aios
  • 405
  • 5
  • 14

1 Answers1

1

providing an identifier for your observer.

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
                            "observer identifier",
                            ringerSwitched,
                            CFSTR("com.apple.springboard.ringerstate"),
                            NULL,
                            CFNotificationSuspensionBehaviorDeliverImmediately);

CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), @"observer identifier");
Reming Hsu
  • 2,215
  • 15
  • 18
  • Thanks for the reply. I found the solution at [link](http://stackoverflow.com/questions/16082100/cfnotificationcenterremoveobserver-observer). As you mentioned, it is not @"observer identifier" rather it could be a c string. i.e "observer identifier" – aios Jun 16 '15 at 12:23
  • Thanks for your mention. – Reming Hsu Jun 17 '15 at 02:07