osx - How to create an event loop in Objective C? -


i'm trying use corebluetooth module list detected bluetooth devices in command-line osx application.

what have looks this, far:

@import corebluetooth;  @interface mycentralmanager : nsobject<cbcentralmanagerdelegate> - (void) centralmanagerdidupdatestate: (cbcentralmanager *) central; - (void) centralmanager:(cbcentralmanager *) central     diddiscoverperipheral:(cbperipheral *) peripheral         advertisementdata:(nsdictionary *) advertisementdata                      rssi:(nsnumber *)rssi; @end  @implementation mycentralmanager - (void) centralmanagerdidupdatestate: (cbcentralmanager *) central {     nslog(@"state changed..."); }  - (void) centralmanager:(cbcentralmanager *) central     diddiscoverperipheral:(cbperipheral *) peripheral         advertisementdata:(nsdictionary *) advertisementdata                      rssi:(nsnumber *)rssi {     nslog(@"discovered %@", peripheral.name); } @end  int main() {     mycentralmanager* mycentralmanager = [[mycentralmanager alloc] init];     cbcentralmanager* cbcentralmanager = [[cbcentralmanager alloc] initwithdelegate:mycentralmanager queue:nil options:nil];      nslog(@"scanning devices !");      [cbcentralmanager scanforperipheralswithservices:nil options:nil];     sleep(5); // wait 5 seconds before stopping scan.     [cbcentralmanager stopscan];      nslog(@"scanning devices ended.");      return 0; } 

now doesn't work @ never "state changed..." nor "discovered ..." log output.

i never written objective c application before i'm missing obvious. if had guess i'm doing wrong assume that:

i'm stuck @ point: don't have gui, nor want 1 couldn't figure out way run event loop (assuming that's missing). how can ?

as said, first attempt objective c, don't afraid state obvious.

simply run thread's run loop

[[nsrunloop currentrunloop] rununtildate:[nsdate datewithtimeintervalsincenow:5]]; 

more information here.

btw: not have declare methods declared in protocol.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -