【发布时间】:2014-04-18 06:19:18
【问题描述】:
我是 iOS 开发新手,正在研究适用于 IOS 的低功耗蓝牙(BLE,蓝牙 4.0)。
我想知道如何在 IOS 7 上使用 Immediate Alert Service。
我可以通过BLE devicescan , connect and discover the Service。
接下来是连接到Immediate alert Service并将characteristics of alert level写入BLE device。
我已经定义了 Immediate alert Service 和 Alert level 的 UUID,如下代码所示。
#define IMMEDIATE_ALERT_UUID @"00001802-0000-1000-8000-00805f9b34fb"
#define ALERT_LEVEL_UUID @"00002a06-0000-1000-8000-00805f9b34fb"
以下代码是关于连接到Immediate alert Service。
[peripheral discoverServices:@[[CBUUID UUIDWithString:IMMEDIATE_ALERT_UUID]]];
连接IMMEDIATE_ALERT_UUID后连接characteristics of alert level的代码如下。
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
for (CBService *service in peripheral.services) {
[peripheral discoverCharacteristics:@[[CBUUID UUIDWithString:ALERT_LEVEL_UUID]] forService:service];
}
}
订阅characteristics of alert level。
- (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];
}
}
但是如何将警报级别写入characteristics of alert level ??
提前致谢。
【问题讨论】:
-
writeValue:forCharacteristic:type:?
标签: ios bluetooth bluetooth-lowenergy core-bluetooth