Tag: cfnotification

如何使用CFNotificationCenterGetDarwinNotifyCenter()发送一个userInfo字典

我需要使用CFNotificationCenterGetDarwinNotifyCenter()发送一个对象,但是我注意到,每当我发送一个通知使用 const void *tkeys[1] = { @"testKey" }; const void *tvalues[1] = { @"testValue" }; CFDictionaryRef userInfo = CFDictionaryCreate(NULL, tkeys, tvalues, 1, NULL, NULL); CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("foo"), object, userInfo, true); 那么我发现在观察者callback中,userInfo字典是NULL。 有什么我在这里失踪? 有没有其他的方式,我可以发送userInfo对象? 我在看http://nshipster.com/inter-process-communication/和分布式通知部分,但是每当我使用: CFNotificationCenterRef distributedCenter = CFNotificationCenterGetDistributedCenter(); 那么每当我尝试它时,我都会收到错误“ Invalid Use of Function错误”。