我想在
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]; }
但是它没有调用委托方法didFailToConnectPeripheral或didConnectPeripheral,我waner有什么问题呢,是代码错误还是IOS8需要一些额外的东西?如何处理,谢谢提前!
这里是我的代码在github,我写一个程序成为服务器,另一个是中央.
解决方法
@Sj评论解决了它,把它复制到一个答案,以防有人会想念它:
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];