蓝牙检索外设时候,要在中心代理执检测到PoweredOn之后才能检索外设,不然找不到。
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
switch (central.state) {
case CBCentralManagerStatePoweredOn:
[self.central scanForPeripheralsWithServices:nil options:nil];
break;
default:
break;
}
}
发送数据,需要保存外设和特征,还要依据特征值properties属性,选择正确的type才能发送出去。
[self.peripheral writeValue:date forCharacteristic:self.writeCharacter type:CBCharacteristicWriteWithoutResponse];
需要接受数据的特征,要注册通知
[peripheral setNotifyValue:YES forCharacteristic:charact];
连接时候报一下这个错:
[CoreBluetooth] API MISUSE: Cancelling connection for unused peripheral <private>, Did you forget to keep a reference to it?
可能你没保存连接的外设导致。