我想让两个运行在不同设备上的程序通过蓝牙与CoreBluetooth进行通信。我可以找到并连接来自经理的外围设备,并且可以浏览连接的外围设备中的服务,但是当我尝试并尝试发现特征时,出现错误The specified UUID is not allowed for this operation.
,并且如预期的那样,该服务的特征为零。UUID不允许在外设didDiscoverCharacteristicsfor服务
这是什么意思?我试图通过指定目标的UUID而没有发现特征,都显示此错误。
这是打印错误的功能。
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
print(error.localizedDescription)//prints "The specified UUID is not allowed for this operation."
if service.characteristics != nil {
for characteristic in service.characteristics! {
if characteristic.uuid == CBUUID(string: "A4389A32-90D2-402F-A3DF-47996E123DC1") {
print("characteristic found")
peripheral.readValue(for: characteristic)
}
}
}
}
这是我寻找外围设备的地方。
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
if peripheral.services != nil {
for service in peripheral.services! {
if service.uuid == CBUUID(string: "dc495108-adce-4915-942d-bfc19cea923f") {
peripheral.discoverCharacteristics(nil, for: service)
}
}
}
}
这是我如何在其他设备上添加服务特性。
service = CBMutableService(type: CBUUID(string:"dc495108-adce-4915-942d-bfc19cea923f"), primary: true)
characteristic = CBMutableCharacteristic(type: CBUUID(string: "A4389A32-90D2-402F-A3DF-47996E123DC1"), properties: .write, value: nil, permissions: .writeable)
service.characteristics = [characteristic]
我尝试了许多不同的属性和权限组合(包括.read/.readable),我得到了同样的错误。
您试图读取您已设置为只写因此当您尝试获得错误的特性并阅读它。 – Paulw11
有道理,但我如何使它可读写?我也将属性更改为.read和.read权限,并且它不会更改任何内容。 – C1FR1