gpt4 book ai didi

ios - IOS 7中alert level的特性怎么写alert level?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:14 25 4
gpt4 key购买 nike

我是 iOS 开发的新手,正在研究适用于 IOS 的低功耗蓝牙(BLE,蓝牙 4.0)。

我想知道如何在 IOS 7 上使用即时警报服务

我可以从 BLE 设备扫描、连接和发现服务。接下来是连接到即时警报服务并将警报级别的特征写入BLE设备

我定义了 Immediate alert ServiceAlert level 的 UUID,如下面的代码。

#define IMMEDIATE_ALERT_UUID           @"00001802-0000-1000-8000-00805f9b34fb"
#define ALERT_LEVEL_UUID @"00002a06-0000-1000-8000-00805f9b34fb"

以下代码是关于连接到即时警报服务

[peripheral discoverServices:@[[CBUUID UUIDWithString:IMMEDIATE_ALERT_UUID]]];

关于连接到 IMMEDIATE_ALERT_UUID 后连接到警报级别特性 的代码就像以下。

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
for (CBService *service in peripheral.services) {
[peripheral discoverCharacteristics:@[[CBUUID UUIDWithString:ALERT_LEVEL_UUID]] forService:service];
}
}

订阅警报级别的特征

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:ALERT_LEVEL_UUID]]) {

// If it is, subscribe to it
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
}

但是alert level的characteristic怎么写alert level呢??

提前致谢。

最佳答案

-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:ALERT_LEVEL_UUID]]){

uint8_t val = 0 //enter the value which you want to write.
NSData* valData = [NSData dataWithBytes:(void*)&val length:sizeof(val)];

[peripheral writeValue:valData forCharacteristic:characteristictype:CBCharacteristicWriteWithResponse];
}

放置参数CBCharacteristicWriteWithResponse 将调用CBPeripheralDelegate 方法- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
}

关于ios - IOS 7中alert level的特性怎么写alert level?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23148548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com