且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

BLE Swift编写特征

更新时间:2023-01-24 07:38:34

您编写的Swift代码不等同于Objective-C示例. data参数应使用二进制"1"而不是字符串"01:00"初始化:

The Swift code written by you is not equivalent to the Objective-C example. The data parameter should be initialized with binary "1" instead of a string "01:00":

var parameter = NSInteger(1)
let data = NSData(bytes: &parameter, length: 1)
peripheral.writeValue(data, for: characteristic, type: .withResponse)

我认为,每当TI文档在引号中指定诸如"01:00"的值时,它们实际上就意味着像0x0100这样的十六进制值,这有点令人困惑.

I think that whenever TI docs specify a value in quotes like "01:00" they really mean a hexadecimal value like 0x0100, which is a bit confusing.