gpt4 book ai didi

ios - CBPeripheral setNotifyValue WithResponse 不调用 didWriteValueForCharacteristic

转载 作者:行者123 更新时间:2023-11-30 13:50:36 26 4
gpt4 key购买 nike

我有一个 BLE 基金可以将数据写入外围服务:

func writeData(data: [Int8]) {
let character = CBMutableCharacteristic(type: cuivienenCharacterUUID, properties: [.Write, .Read, .Notify], value: nil, permissions: [.Readable, .Writeable])
test_peripheral.writeValue(NSData(bytes: data, length: data.count), forCharacteristic: character, type: .WithResponse)
test_peripheral.setNotifyValue(true, forCharacteristic: character)
}

我已经初始化了 test_peripheral 并将其委托(delegate)设置为 self。但是test_peripheral.writeValue从未打过电话func peripheral(peripheral: CBPeripheral, didWriteValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) 。我连错误消息都收不到!

test_peripheral.setNotifyValue也是如此。它从不调用func peripheral(peripheral: CBPeripheral, didUpdateNotificationStateForCharacteristic characteristic: CBCharacteristic, error: NSError?)

我的代码有什么问题吗?

最佳答案

CB特性

test_peripheral.writeValue(NSData(bytes: data, length: data.count), forCharacteristic: character, type: .WithResponse)

不应由您自己的代码初始化。您应该在

中找到您的 CBCharacteristic
func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?)

然后使用它。

关于ios - CBPeripheral setNotifyValue WithResponse 不调用 didWriteValueForCharacteristic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34336949/

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