Hi,
I am trying to print image via bluetooth with following swift code:
func printImage(){
var serialNumber = ""
let sam: EAAccessoryManager = EAAccessoryManager.shared()
let connectedAccesories = sam.connectedAccessories
for accessory in connectedAccesories {
if accessory.protocolStrings.index(of: zebraProtocol) != nil {
serialNumber = accessory.serialNumber
break;
}
}
let printerConn = MfiBtPrinterConnection.init(serialNumber: serialNumber)
_ = printerConn!.open()
let printer = try! ZebraPrinterFactory.getInstance(printerConn)
let image = UIImage(named: "image1")?.cgImage!
DispatchQueue.global(qos: .background).async {
try! printer.getGraphicsUtil()?.print(image, atX: 0, atY: 0, withWidth: 400, withHeight: 300, andIsInsideFormat: true)
}
}
But it gives this error:
ERROR - /BuildRoot/Library/Caches/com.apple.xbs/Sources/ExternalAccessory/ExternalAccessory-383.250.1/EAOutputStream.m:-[EAOutputStream write:maxLength:] - 332 failed to write because stream does not have space available
How should i print images with ZQ510 ?
Thanks
2 Replies
Hello sir,
DID you get any solution for this.Please help me am also getting the same issue!
Please try to use false for andIsInsideFormat variable, because you wanted to print the image alone. We use true for andIsInsideFormat variable when we try to print the image inside a label format as an integral part of the label. Hope this helps.
try! printer.getGraphicsUtil()?.print(image, atX: 0, atY: 0, withWidth: 400, withHeight: 300, andIsInsideFormat: false)
Another note I'd like to add. We would see "failed to write because stream does not have space available" error when we call the Link-OS SDK API in a UI thread. You probably got this error even prior to calling DispatchQueue.global() statement. It is recommended to use non-UI thread to call Link-OS SDK API. Please try to move the MfiBtPrinterConnection.init(), ZebraPrinterFactory.getInstance() and printer.getGraphicsUtil()?.print() all together to a background thread.