Why use coreBluetooth connectPeripheral did not call delegate methods in IOS8

江枫思渺然 提交于 2019-11-28 12:03:49

@Sj comment solved it for me, copying it into an answer in case someone will miss it:

Did u tried storing the peripheral object in an ivar and then connect to it? ie self.discoveredPeripheral = peripheral; [self.centralManager connectPeripheral:self.discoveredPeripheral options:nil];

I am using TemperatureSensor iOS sample app which didDiscoverPeripheral did not called. By reference the flow of Heart Rate Monitor Mac sample app. Please make sure the run sequence of code is:

1. centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
2. - (void) centralManagerDidUpdateState:(CBCentralManager *)central
3. [centralManager scanForPeripheralsWithServices:... 

- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:... will be called afterwards.

Call the connect method only once and wait for the connection delegate response. The above code which you posted will call the connect method more often (when ever it discover the peripheral)

if(!self.detectedBLE){ [self.centralManager stopScan]; self.detectedBLE = peripheral; [self.centralManager connectPeripheral:self.detectedBLE options:nil]; }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!