I'm sending Strings from Mobile Device via BLE to an specific Hardware. Depending on the version, a header byte must be prepended (0x01). My working Java version (Android) looks like this:
private void writeBluetooth(String msg){
this.btResponseHandler.postDelayed(btResponseHandlerRunnableCode, 500);
if (xBleHardwareVersion == 1)
{
byte[] result = concat(msg.getBytes(), new byte[] { 0x0d, 0x0a });
peripheral.writeCharacteristic(V1_SERVICE_UUID,V1_TX_CHARACTERISTIC,result, WriteType.WITHOUT_RESPONSE);
} else if (xBleHardwareVersion == 2) {
byte[] result = concat(new byte[] { 0x01 }, msg.getBytes(), new byte[] { 0x0d, 0x0a });
peripheral.writeCharacteristic(V2_SERVICE_UUID,V2_TX_CHARACTERISTIC,result, WriteType.WITHOUT_RESPONSE);
}
}
I'm very new at the Swift language so my question: How to get this word with Swift on IOS?
Best regards