iOS 8蓝牙LE Central无法为特性2A06写入值

时间:2014-11-27 15:46:17

标签: ios objective-c bluetooth bluetooth-lowenergy core-bluetooth

我正在开发一款iPhone应用程序,需要在iOS 7.0和8.0上使用CoreBluetooth框架支持Immediate Alert service的蓝牙低功耗设备上写入价值。与设备的连接工作正常,但每当我尝试在设备上写入值时,没有任何事情发生(该值未保存在设备上。因此,设备没有响铃)。 以下是用于写入值的代码:

+ (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];
}

执行上述代码之前的设备日志和状态:

- (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

我使用BLE Utility app测试了我的蓝牙设备并且工作正常。

1 个答案:

答案 0 :(得分:0)

final List<Foo> toRemove = new ArrayList<>();

for (Foo a : list)
{
    for (Foo b : list)
    {
        if (something)
        {
            toRemove.add(b);
        }
    }
}
list.removeAll(toRemove);