獲取的參數轉換後標籤錯誤斯威夫特:
參數標籤「(字節長度:, :)」不匹配任何可用的重載參數標籤錯誤
有效載荷分配:
let payload = Data(bytes: bytes, length: length)
if characteristic.uuid.isEqual(CBUUID(string: TRANSFER_CHARACTERISTIC_UUID)) {
print("Writing to characteristic \(characteristic)")
let zpl: String = "^XA^FO50,50^ADN,36,20^FDHELLO WORLD^FS^XZ"
let bytes = zpl.utf8
let length: size_t = (zpl.characters.count ?? 0)
let payload = Data(bytes: bytes, length: length)
print("Writing payload: \(payload) length of \(length)")
//peripheral.writeValue(payload, forCharacteristic: characteristic, type: CBCharacteristicWriteWithResponse)
peripheral.writeValue(payload, for: characteristic, type: CBCharacteristicWriteType)
}
及以下:
textview.text = String(data, encoding: String.Encoding.utf8)
if (stringFromData == "EOM") {
// We have, so show the data,
textview.text = String(data, encoding: String.Encoding.utf8)
// Cancel our subscription to the characteristic
peripheral.setNotifyValue(false, for: characteristic)
// and disconnect from the peripehral
centralManager?.cancelPeripheralConnection(peripheral)
}
建議?
是否有你爲什麼不使用'zpl.data(使用:.utf8)'將'String'轉換爲'Data'的原因? – FelixSFD
@FelixSFD =)可能是因爲我很新的菲利克斯。我會看看那個。感謝您的建議。向你們學習很多。 – JLanders