为什么在IOS8中使用coreBluetooth connectPeripheral没有调用委托方法

我想在IOS8中使用CoreBluetooth.framework来实现数据传输,我在下面的方法中发现了外设并尝试连接外设。

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { NSLog(@"Discover name : %@", peripheral.name); [self.centralManager connectPeripheral:peripheral options:nil]; } 

但它没有调用委托方法didFailToConnectPeripheraldidConnectPeripheral ,我waner有什么问题呢,是代码错误还是IOS8需要一些额外的东西? 如何处理,提前致谢!

这里是我在github的代码,我写了一个程序作为服务器,另一个是中央。

@Sj评论为我解决了它,把它复制成一个答案,以防有人会错过它:

你试过把外围的物体存放在伊娃里,然后连接到它吗? 即self.discoveredPeripheral = peripheral; [self.centralManager connectPeripheral:self.discoveredPeripheral options:nil];

我正在使用didDiscoverPeripheral没有调用的TemperatureSensor iOS示例应用程序 。 通过参考心率监测Mac样本应用程序的stream量。 请确保代码的运行顺序是:

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

- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:...将被调用。

只调用connect方法一次,然后等待连接委托响应。 您发布的上述代码将更经常地调用connect方法(当它发现外设时)

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