我有一个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并将它的委托设置为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?)
我的代码出了什么问题?
发布于 2015-12-17 23:00:29
CBCharacteristic in
test_peripheral.writeValue(NSData(bytes: data, length: data.count), forCharacteristic: character, type: .WithResponse)不应该由你自己的代码初始化。您可以在以下位置找到您的CBCharacteristic
func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?)然后使用它。
https://stackoverflow.com/questions/34336949
复制相似问题