2017-06-29 33 views
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 
} 
+0

这可能有所帮助:https://stackoverflow.com/a/40278391/1187415。 –

回答

0

找到哪个CBCharacteristic属性写入。

let data:[UInt8] = [0x01, 0x03, 0x012, 0x01] 
    let writeData = Data(bytes: data) 

    self.selectPeripheral.writeValue(writeData, for: writeCharacteristic, 
    type: WithResponse) 
相关问题