I am working on an iPhone app and need to write value on the bluetooth low energy device that support Immediate Alert service using CoreBluetooth framework on iOS 7.0 and 8.0. Connection with the device working perfectly but whenever i try to write a value on the device nothing is happening (the value is not saved on device. So, device is not ringing). Below is the code used for writing value:
+ (void)writeValueForCharacteristic:(CBCharacteristic *)characteristic peripheral:(CBPeripheral *)peripheral alarm:(BOOL)alarm
{
NSData * data = nil;
if (alarm) {
uint8_t value = 2;
data = [NSData dataWithBytes:&value length:sizeof(value)];
} else {
uint8_t value = 0;
data = [NSData dataWithBytes:&value length:sizeof(value)];
}
[peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithoutResponse];
}
Logs and status of device before the execution above code:
- (void)beginAlarm
{
NSLog(@"characteristic : %@",discAlertCharacteristic);
NSLog(@"peripheral : %@",discPeripheral);
NSLog(@"service : %@",service);
[BluetoothUtility writeValueForCharacteristic:discAlertCharacteristic peripheral:discPeripheral alarm:YES];
}
characteristic : CBCharacteristic: 0x146ea8d0, UUID = 2A06, properties = 0x14, value = (null), notifying = NO service : CBService: 0x146ecc90, isPrimary = YES, UUID = 1802 peripheral : CBPeripheral: 0x146dd110, identifier = B0A195DC-7273-B3F5-BA70-0219A61F8904, name = LA-TAG a87, state = connected
I have tested my Bluetooth device using BLE Utility app and its working properly.
discoverCharacteristics:forService:
onperipheral
beforebeginAlarm
is called? – Michał Ciuba