Converting NSNotificationCenter events to Signals
-
To provide a little more context, I would like a specific class in my main application to receive NSNotificationCenter events from the third-party framework. This class will handle the event and emit the necessary signals as defined in my abstract base class interface, to the main application.
-
Hi,
Why not make the wrapper a QObject ?
-
@SGaist I actually did do that in the end. I am still left with the problem of registering my handlers for NSNotificationCenter events. I am having trouble defining "self". I do not know how to define "Self" as an instance of my class. I found an example in Git:
platformios.mm
But I don't want to be dealing with application level events, only events generated by my third party library.Do I have to define a delegate?
-
I believe I have solved my problem. I haven't tested it yet since the first call to the third-party library throws an exception. I am, however able to register my notification handler and confirm that its being executed
@interface EventDelegate : NSObject //UIResponder { UtasCommunicationHandler* m_comm_handler; } @end @implementation EventDelegate - (id) initWithObject:(UtasCommunicationHandler*) comm_handler { self = [super init]; if (self) { m_comm_handler = comm_handler; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConnectedTIMList:) name:kUTCTIMNotificationUpdateConnectedTIMList object:nil]; } return self; } -(void)updateConnectedTIMList:(NSNotification*)notification { DNA_INFO("RECEIVED TIM CONNECTION") } @end
-
Great !
What was the problem ?
-
So you got something like "unrecognized selector"
-
@SGaist Actually no. The compiler never complained. It just caused an unhandled exception to be thrown, which appeared to be caused by the call which set up the notification. If I had looked at the exception details, I might have seen the message you suggested, but I noticed the error, fixed it and the problem went away.
-
The important point is that you could solve it :)