Have you checked the doc of CFNotificationCenterGetDarwinNotifyCenter?
Discussion
... As with distributed notifications, the main thread's run loop must be running in one of the common modes (usually kCFRunLoopDefaultMode) for Darwin-style notifications to be delivered.
Please try adding CFRunLoopRun(); at the end of your code:
int main(int argc, const char * argv[]) {
// Add Observer
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, //observer
myCallback, //callback
CFSTR("sanity_check"), //event name
NULL, //object
CFNotificationSuspensionBehaviorDeliverImmediately
);
// Post notification 1
CFNotificationCenterPostNotification(
CFNotificationCenterGetDarwinNotifyCenter(), // center
CFSTR("sanity_check"), // event name
NULL, //object
NULL, //userinfo dictionary
true
);
// Post notification 2
notify_post("sanity_check");
CFRunLoopRun(); //<-
return 0;
}
Topic:
App & System Services
SubTopic:
Core OS
Tags: