【发布时间】:2020-01-13 05:55:08
【问题描述】:
我尝试使用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] [main] > 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 8703E44D2-42EE- CC5D-10675DF5DB09。 2020-01-13 00:30:24.253 [Bluejay] [main] > 写入特征失败:0000FFB2-0000-1000-8000-00805F9B34FB,服务:0000FFB0-0000-1000-8000-00805F9B34FB 上 845E44D2-4-EE-4-B34FB CC5D-10675DF5DB09 出现错误:不允许写入。 “无法写入传感器位置并出现错误:不允许写入。”
结果显示:无法写入传感器位置并出现错误:不允许写入。
注意:项目原形式 swift 3 升级为 swift 4
【问题讨论】: