Swift BLE 设备 - 写入值

标签 swift bluetooth-lowenergy

我有 0x010303757372707764 可以写入 ble 设备。我知道使用 writeValue 方法

peripheral.writeValue(data, for: characteristics[i], type: .withResponse)

但我想写入 0x010303757372707764 作为数据。我怎么做?

如果您需要更多信息,请告诉我!谢谢!

最佳答案

使用数据的UInt8序列初始值设定项:

init<S>(_ elements: S) where S : Sequence, Self.Element == S.Element

对于您的示例,这将是:

let data = Data([0x01, 0x03, 0x03, 0x75, 0x73, 0x72, 0x70, 0x77, 0x64])

关于Swift BLE 设备 - 写入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59295901/

相关文章:

raspberry-pi - Raspberry Pi iBeacon 扫描解析响应

ios - 如果快速填充文本字段,则启用按钮

ios - 结构的值在初始声明后未更新

swift - 如何在 Swift 中等待函数调用结束

ios - 如何使用 Alamofire Swift 读取 Content-Length HTTPResponse

ios - 蓝牙经典连接感知

ios - 如何用其他方法识别通过蓝牙扫描的设备

android - 以编程方式,如何识别信标是属于 Eddystone 还是 iBeacon?

bluetooth - createBond 并不总是显示引脚对话框

ios - 无法在 (UIView) 上设置 (cornerRadius) 用户定义的检查属性