Find My Device
How to implement the Find My Device for the v button in iOS using the Immediate Alert Service. We are unable to get this feature working by using the sample code provided or the code below. Do you have any suggestions for us at all? The same approach works fine in Android but on iOS we are getting:
Below is the code I am using for Immediate Alert Service:
#define BLE_SIG_IMMEDIATE_ALERT_SERVICE_UUID @"00001802-0000-1000-8000-00805f9b34fb"
#define BLE_SIG_IMMEDIATE_ALERT_CHAR_UUID @"00002a06-0000-1000-8000-00805f9b34fb"
-(void)findPeripheral:(CBPeripheral *)peripheral
{
///Send Immediate alert to peripheral
for (CBService *service in peripheral.services) {
if([service.UUID isEqual:[CBUUID UUIDWithString:BLE_SIG_IMMEDIATE_ALERT_SERVICE_UUID]])
{
for (CBCharacteristic *aChar in service.characteristics)
{
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:BLE_SIG_IMMEDIATE_ALERT_CHAR_UUID]])
{ // 2
NSLog(@"Characteristic matched, sending immediate alert");
///The V.BTTN alert behavior is as follow:
//00 No Alert.
//01 Chirp every 2 seconds for 20 seconds.
//02 Chirp + blink red LED every 2 seconds for 20 seconds
//UInt8 chirpAndBlink = 0x02;
//NSData *data = [NSData dataWithBytes:(void*)&chirpAndBlink length:sizeof(chirpAndBlink)];
char chirpAndBlink = 0x02;
NSData *data = [[NSData alloc] initWithBytes:(Byte[]){chirpAndBlink} length:1];
[peripheral writeValue:data forCharacteristic:aChar type:CBCharacteristicWriteWithResponse];
}
}
}
}
}
Note: I tried with below constant as well, the problem is with writing the value
#define BLE_SIG_IMMEDIATE_ALERT_SERVICE_UUID @"1802"
#define BLE_SIG_IMMEDIATE_ALERT_CHAR_UUID @"2a06"
-
Official comment
These 2 lines
NSData *data = [[NSData alloc] initWithBytes:(Byte[]){chirpAndBlink} length:1];
[peripheral writeValue:data forCharacteristic:aChar type:CBCharacteristicWriteWithResponse];
Should be
NSData *data = [[NSData alloc] initWithBytes:&chirpAndBlink length:1];
[peripheral writeValue:data forCharacteristic:aChar type:CBCharacteristicWriteWithoutResponse];
Comment actions
Please sign in to leave a comment.
Comments
1 comment