我试图用Bluejay库将命令表格iphone写入BT ble,如下所示
func write(command: Command) {
let weakSelf = self
Utils.delay(0.3) {
debugPrint("[\(self.getTodayString())]Writing to device: \(command.string)");
debugPrint("hunter: weakSelf.bdeCharacteristics = \(weakSelf.bdeCharacteristics) and bdeService= \(weakSelf.bdeService) , and isConnected = \(weakSelf.isConnected)");
weakSelf.bluejay.write(to: weakSelf.bdeCharacteristics, value: command.string) { (result) in
switch result {
case .success:
debugPrint("Write to sensor location is successful.")
//case .cancelled:
//debugPrint("Cancelled write to sensor location.")
case .failure(let error):
debugPrint("Failed to write to sensor location with error: \(error.localizedDescription)")
}
}
}
}
在写命令时,记录如下:
“ [2020-1-13 0:30:24]正在写入设备:SystemOn:\ n \ 0”
2020-01-13 00:30:24.247 [Bluejay] [main]>请求写入特征:0000FFB2-0000-1000-8000-00805F9B34FB,服务:0000FFB0-0000-1000-8000-00805F9B34FB ...
2020-01-13 00:30:24.248 [Bluejay] [main]>队列将启动Bluejay.DiscoverService ...
2020-01-13 00:30:24.248 [Bluejay] [main]>队列已删除Bluejay.DiscoverService,因为它已完成。
2020-01-13 00:30:24.249 [Bluejay] [main]>队列为空,没有任何更新。
2020-01-13 00:30:24.249 [Bluejay] [main]>队列将启动Bluejay.DiscoverCharacteristic ...
2020-01-13 00:30:24.250 [Bluejay] [主]> Bluejay.WriteCharacteristic已添加到具有UUID:15A4B937-7BCB-4F02-B6D5-96E04D480320的队列中。
2020-01-13 00:30:24.250 [Bluejay] [main]>队列已删除Bluejay.DiscoverCharacteristic,因为它已完成。
2020-01-13 00:30:24.251 [Bluejay] [main]>队列将启动Bluejay.WriteCharacteristic ...
2020-01-13 00:30:24.252 [Bluejay] [main]>开始写入特征:0000FFB2-0000-1000-8000-00805F9B34FB,服务:0000FFB0-0000-1000-8000-00805F9B34FB on 845E44D2-42EE-7B03- CC5D-10675DF5DB09。
2020-01-13 00:30:24.253 [Bluejay] [main]>无法写入特征:0000FFB2-0000-1000-8000-00805F9B34FB,服务:0000FFB0-0000-1000-8000-00805F9B34FB on 845E44D2-42EE-7B03- CC5D-10675DF5DB09,错误:不允许写入。
“无法写入传感器位置,并出现错误:不允许写入。”
结果显示:错误地写入传感器位置失败:不允许写入。
注意:将项目原始表格swift 3升级到swift 4
最佳答案
根据
i found this solution
迅速4后CBCharacteristicWriteWithResponse已更改为WithoutResponse
所以我用withResponse替换了withwithResponse,这个问题解决了。