aios
aios

Reputation: 425

CFNotificationCenterRemoveEveryObserver not removing the observer

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);

Upvotes: 2

Views: 415

Answers (1)

Reming Hsu
Reming Hsu

Reputation: 2225

providing an identifier for your observer.

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

CFNotificationCenterRemoveEveryObserver(CFNotificationCenterGetDarwinNotifyCenter(), @"observer identifier");

Upvotes: 1

Related Questions