gpt4 book ai didi

iOS BLE "Characteristic User Description"

转载 作者:行者123 更新时间:2023-11-30 12:35:05 27 4
gpt4 key购买 nike

尝试使用以下函数从特征中检索可读信息:

peripheral.discoverDescriptors(for: characteristic)

稍后的委托(delegate)方法:

func peripheral(_ peripheral: CBPeripheral, didDiscoverDescriptorsFor characteristic: CBCharacteristic, error: Error?) 

被调用,但如何获取字符串描述?当我从描述符中读取值时,它总是nil

let descriptors = characteristic.descriptors! as [CBDescriptor]
for descriptor in descriptors {
print("\(#function): descriptor = \(descriptor) UUID = \(descriptor.uuid) value = \(descriptor.value)")
}

但是,如果我正在浏览并连接 BLE 扫描仪,它可以读取人类可读的特征描述符。

最佳答案

读取描述符是一个两步过程,很像发现然后读取特征。

尝试:

public func peripheral(_ peripheral: CBPeripheral, didDiscoverDescriptorsFor characteristic: CBCharacteristic, error: Error?) {
guard let descriptors = characteristic.descriptors else { return }

for descr in descriptors {
peripheral.readValue(for: descr)
}
}

然后填写以下空白:

public func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor descriptor: CBDescriptor, error: Error?) {
switch descriptor.uuid.uuidString {
case CBUUIDCharacteristicExtendedPropertiesString:
guard let properties = descriptor.value as? NSNumber else {
break
}
print(" Extended properties: \(properties)")
case CBUUIDCharacteristicUserDescriptionString:
guard let description = descriptor.value as? NSString else {
break
}
print(" User description: \(description)")
case CBUUIDClientCharacteristicConfigurationString:
guard let clientConfig = descriptor.value as? NSNumber else {
break
}
print(" Client configuration: \(clientConfig)")
case CBUUIDServerCharacteristicConfigurationString:
guard let serverConfig = descriptor.value as? NSNumber else {
break
}
print(" Server configuration: \(serverConfig)")
case CBUUIDCharacteristicFormatString:
guard let format = descriptor.value as? NSData else {
break
}
print(" Format: \(format)")
case CBUUIDCharacteristicAggregateFormatString:
print(" Aggregate Format: (is not documented)")
default:
break
}
}

字符串常量和关联的数据类型来自概述表 here .

根据我(有限的)经验,描述符并没有揭示任何特别有趣的东西。

关于iOS BLE "Characteristic User Description",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42984737/

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