首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CBPeripheral setNotifyValue WithResponse请勿调用didWriteValueForCharacteristic

CBPeripheral setNotifyValue WithResponse请勿调用didWriteValueForCharacteristic
EN

Stack Overflow用户
提问于 2015-12-17 22:25:30
回答 1查看 842关注 0票数 0

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

代码语言:javascript
复制
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并将它的委托设置为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?)

我的代码出了什么问题?

EN

回答 1

Stack Overflow用户

发布于 2015-12-17 23:00:29

CBCharacteristic in

代码语言:javascript
复制
test_peripheral.writeValue(NSData(bytes: data, length: data.count), forCharacteristic: character, type: .WithResponse)

不应该由你自己的代码初始化。您可以在以下位置找到您的CBCharacteristic

代码语言:javascript
复制
func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?)

然后使用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34336949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档