0

I am trying to send data to a ble, but my device only accepts byte arrays. How do I convert data to byte array and send it in 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
}
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
shivadeep
  • 68
  • 1
  • 11

1 Answers1

1

Find to which CBCharacteristic property is write.

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

  self.selectPeripheral.writeValue(writeData, for: writeCharacteristic, 
  type: WithResponse)
Deepak Tagadiya
  • 2,187
  • 15
  • 28