出現(xiàn)中文亂碼靶端,大概率就是編碼問題導(dǎo)致的,使用GBK/GB2312進(jìn)行編碼
let printStr = "! 0 200 200 100 1\r\nPAGE-WIDTH 576\r\nUNDERLINE ON\r\nSETBOLD 0\r\nSETMAG 1 1\r\nTEXT 24 0 0 0 jdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好\r\njdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好\r\njdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好\r\njdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好\r\njdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好jdfkajdkjf你好\r\nPRINT\n"
let enc = CFStringConvertEncodingToNSStringEncoding(UInt32(CFStringEncodings.GB_18030_2000.rawValue))
let strData = printStr.data(using: String.Encoding(rawValue: enc))