0
我想发送数据到一个ble,但我的设备只接受字节数组。如何将数据转换为字节数组并在Swift 3中发送?如何发送一个字节数组到Swift 3中?
print("hex value is",hexRepresentation)
print("pairing code",pairingcode)
var aaa = calcchecksum(data:"4A6BF961585C3F86DCEB562CEC51A4CE")
if let auxData = (hexRepresentation+"4A6BF961585C3F86DCEB562CEC51A4CE"+aaa).data(using: .utf8), let lChar = self.mainCharacteristic {
let bytearraydata = [UInt8](auxData) as Data?
aPeripheral.writeValue(bytearraydata, for: lChar, type: .withResponse
}
这可能有所帮助:https://stackoverflow.com/a/40278391/1187415。 –