Swift 不允许快速蓝牙写入
我尝试用Bluejay库将命令从iphone写入BT ble,如下所示Swift 不允许快速蓝牙写入,swift,bluetooth-lowenergy,Swift,Bluetooth Lowenergy,我尝试用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.bdeCharacteri
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。发现特征。。。
2020-01-13 00:30:24.250[Bluejay][main]>Bluejay.WriteCharacteristic添加到UUID为15A4B937-7BCB-4F02-B6D5-96E04D480320的队列中。
2020-01-13 00:30:24.250[Bluejay][main]>队列已删除Bluejay.DiscoveryCharacteristic,因为它已完成。
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,地址:845E44D2-42EE-7B03-CC5D-10675DF5DB09。
2020-01-13 00:30:24.253[Bluejay][main]>未能写入特征:0000FFB2-0000-1000-8000-00805F9B34FB,服务:0000FFB0-0000-1000-8000-00805F9B34FB,在845E44D2-42EE-7B03-CC5D-10675DF5DB09上,错误:不允许写入。
“无法写入传感器位置,错误:不允许写入。”
结果显示:写入传感器位置失败,出现错误:不允许写入。
注:项目原始表格swift 3升级为swift 4
CBCharacteristicWriteWithResponse在swift 4之后已更改为withoutResponse
所以我用withoutResponse替换为withoutResponse,这个问题就解决了