Re: CFNotificationCenter ./. NSNotificationCenter
Re: CFNotificationCenter ./. NSNotificationCenter
- Subject: Re: CFNotificationCenter ./. NSNotificationCenter
- From: Dave Keck <email@hidden>
- Date: Sat, 27 Feb 2010 02:59:13 -1000
Future inquires regarding CF/Cocoa should be sent to Cocoa-dev.
> Now I'm trying to get the data I received out of my thread.
> I'm posting a CFNotification to the local center.
>
> CFNotificationCenterPostNotification(
> CFNotificationCenterGetLocalCenter(), CFSTR("news"), NULL, nfodict,
> false);
Why are you using CFNotificationCenter to post the notification
instead of NSNotificationCenter? This is probably what you want:
[[NSNotificationCenter defaultCenter] postNotificationName:
@"news" object: nil userInfo: nfodict];
If you want to send the notification to another thread, you can use a
trampoline method with -performSelector:onThread:... Remember that
notifications are delivered on the same thread that
-postNotificationName:... was called.
> But in some other thread I'm not receiving it.
> [[NSNotificationCenter defaultCenter] addObserver:self
> selector:@selector(NoteCallBack:) name:@"news" object:NULL];
I'm betting you're not running the run loop in your secondary thread.
Here's an example of how to use NSNotificationCenter to deliver a
notification on a secondary thread:
http://pastie.org/845544
Delivering a notification on the main thread (from a secondary thread)
is considerably easier thanks to -performSelectorOnMainThread:...
> In two threads (in one application) do I need to use the distibuted
> center?
No - NSDNC should be reserved for IPC between separate processes. NSNC
works fine for inter-thread communication.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden