I developed a program which establish communication by BLE. it works normal between mac 、ios、mac。but when try to establish communication between mac osx and android 5.0.x ,it fail。Then I debuged it,it maybe bug:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
if (error)
{
NSLog(@"Discovered characteristics for %@ with error: %@", [service.UUID UUIDString], [error localizedDescription]);
return;
}
for (CBCharacteristic *characteristic in service.characteristics)
{
NSLog(@"characteristics uuid:%@",[characteristic.UUID UUIDString]);
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:READ_CHARACTERISTIC_UUID]]) {
/
int properties = characteristic.properties;
/
int notifyable = properties & 0x10;
if(notifyable!=0){
NSLog(@"准备监听characteristics uuid:%@",[characteristic.UUID UUIDString]);
[peripheral discoverDescriptorsForCharacteristic:characteristic];
/
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
}
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:WRITE_CHARACTERISTIC_UUID]]) {
Device *tmpDevice = [[Device alloc]init];
tmpDevice.mPeripheral = peripheral;
tmpDevice.mName = peripheral.name;
tmpDevice.isConnected = TRUE;
tmpDevice.mWriteCharacteristic = (CBMutableCharacteristic *)characteristic;
mTestDevice = tmpDevice;
[mConnectedDevices addObject:mTestDevice];
}
}
}
- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
if(error)
{
NSLog(@"监听characteristics uuid:%@失败",[characteristic.UUID UUIDString]);
NSLog(@"ERROR CODE %ld\n Error changing notification state: %@",(long)error.code,[error localizedDescription]);
}else{
NSLog(@"设置监听特征%@成功",[characteristic.UUID UUIDString]);
}
/
if (![characteristic.UUID isEqual:[CBUUID UUIDWithString:NOTIFY_READ_CHARACTERISTIC_UUID]]) {
return;
}
/
if (characteristic.isNotifying) {
NSLog(@"Notification began on %@", characteristic);
}
else {
NSLog(@"Notification stopped on %@. Disconnecting", characteristic);
[self.mCBCentralManager cancelPeripheralConnection:peripheral];
}
}
always unknown error
2015-06-13 14:28:47.303 Demo[1742:274412] 监听characteristics uuid:2FF1E1FA-558B-EE5D-24D0-FF0A068DC1CC失败
2015-06-13 14:28:47.303 Demo[1742:274412] ERROR CODE 0
Error changing notification state: Unknown error.
so mac osx can not goto auto
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
can anyone help me?