【发布时间】:2016-01-11 08:03:15
【问题描述】:
我正在从数据库中检索数据记录,然后将每条记录写入 BLE 设备的CBCharacteristic。编写实现,
for service in self.connectedPeripheral!.services! {
for characteristic in service.characteristics! {
if characteristic.UUID.UUIDString == "1111" {
self.connectedPeripheral!.writeValue(dataRecord, forCharacteristic: characteristic, type: .WithResponse)
}
}
}
现在CBPeripheral 的didWriteValueForCharacteristic 方法被nil NSError 调用。所以写成功了。但是我们如何跟踪写入 BLE 设备的数据记录。因为我需要从数据库中删除这条成功写入的记录。在CBCharacteristic 文档中,当我们开始对BLE 进行写入操作时,我找不到任何可以设置为数据库record_id 的属性。其中大部分是只读的。
func peripheral(peripheral: CBPeripheral, didWriteValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) {
print("write characteristic: \(characteristic)")
// Need to track the record here So it can be removed from database
}
【问题讨论】:
标签: ios core-bluetooth cbperipheral