pqvst
pqvst

Reputation: 4444

Delegates in non-cocoa application

I have been trying to implement a bluetooth service in a "non-cocoa" OSX application (i.e. a C++ application which also uses Objective-C++ code and links to Cocoa libraries). At this stage, the application just runs as a terminal program and does not have a NSApplication instance nor an AppDelegate.

The IOBluetooth framework uses delegates to receive callbacks when for example data is available in a RFCOMM channel. However, these delegates don't fire in my non-cocoa application. When I use the same code in a cocoa application the delegates fire as expected.

I am wondering how exactly delegates work. I imagine they are probably some what similar to messages in Windows (e.g. using a message queue/pump). I found something called a NSRunLoop. Would implementing NSRunLoops in my threads make the delegates work?

Or could it be something else that is causing my delegates to not fire in the non-cocoa case?

Upvotes: 0

Views: 75

Answers (1)

trojanfoe
trojanfoe

Reputation: 122401

I would imagine that you do need a run loop in order to get this working. I have been playing with command-line Foundation programs written in Objective-C and have written a simple class to manage the run loop.

It's open source and available here. Check out the examples; it might be all you need.

Upvotes: 1

Related Questions