I'm trying to learn how to use Darwin Notifications, and I'm having trouble getting my callback function to trigger. I've been writing a command line tool just to learn how to get Darwin notifications working, but eventually will use them in an iPhone app. I have sample code below; can anyone with Darwin Notifications experience point out what am I doing wrong?
//callback
static void myCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
NSLog(@"In callback function");
}
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");
return 0;
}