简体   繁体   English

BLE写特性iOS

[英]BLE write characteristic ios

It's me again 又是我

I got connection between a mini thermal printer and a iOS device, everything is fine except for the number of letters that it prints. 我在微型热敏打印机和iOS设备之间建立了连接,除了打印的字母数量之外,其他一切都很好。

If a want to print a long string it just print a few of them.And the worst is this. 如果要打印一个长字符串,只打印其中几个字符串,最糟糕的是这样。

For example if i want to print this "aaaaa1aaaa1" and this "bbbbb2bbbb2" 例如,如果我要打印此“ aaaaa1aaaa1”和此“ bbbbb2bbbb2”
the result is "aaaaa1" "aaaa1b" "bbbb2b" "bbbb2" (each block is separated) 结果为“ aaaaa1”,“ aaaa1b”,“ bbbb2b”,“ bbbb2”(每个块分开)

this is the code for the print button 这是打印按钮的代码

@IBAction func btnImprimironClick(_ sender: Any) {
        let mensaje = "-----Guillermo Celi (CREO-SUMA) dijo que el primer mandatario está dentro del plazo para remitir un alcance al veto parcial, y pueda “objetar la creación de los cuerpos de seguridad para la custodia de burócratas”. Explicó que su bancada está en contra de ese capítulo del proyecto porque es inconstitucional, y que esa tarea le corresponde a las Fuerzas Armadas y la Policía Nacional. La comisión de Soberanía y Asuntos Internacionales, presidida por Doris Soliz (AP), se allanó al veto parcial del Ejecutivo. Ella señaló que lo único que cabe es acoger el informe pese al pedido de la oposición."
        var datos = mensaje.data(using: .utf8)!
        self.printer.writeValue(datos , for: characteristic1, type: CBCharacteristicWriteType.withoutResponse)

Please help me with this, could be something wrong whit the code or the utf8 请帮助我,代码或utf8可能有误

Thanks. 谢谢。

For some reason it's about the coding format, first I use the utf8 because its a standard but I change to macOSRoman and work perfectly. 出于某种原因,它与编码格式有关,首先我使用utf8,因为它是标准格式,但我改为使用macOSRoman并可以正常工作。

static func printText(text: String)
    {
        let text = "Some long paragraph in spanish version."
        let byteArray = text.data(using:String.Encoding.macOSRoman)
        self.printer.writeValue(byteArray! , for: characteristic1, type: CBCharacteristicWriteType.withoutResponse)
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM