我想讓兩個運行在不同設備上的程序通過藍牙與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