简体   繁体   中英

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.

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"
the result is "aaaaa1" "aaaa1b" "bbbb2b" "bbbb2" (each block is separated)

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

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.

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)
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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