【发布时间】:2015-03-31 20:42:59
【问题描述】:
我正在打印到 QLn420,它在调试器下运行良好,或者当非常少量的 ZPL 传递给它时,但当我不在调试器下运行应用程序时它会失败。该代码与 Zebra 的演示代码 (https://km.zebra.com/kb/index?page=content&id=WH122&actp=LIST) 基本相同,只是 dispatch_async 在调用堆栈中更早地执行。
NSString *serialNumber = [ZebraPrintManager getBluetoothSerial];
// Instantiate connection to Zebra Bluetooth accessory
id<ZebraPrinterConnection, NSObject> thePrinterConn = [[MfiBtPrinterConnection alloc] initWithSerialNumber:serialNumber];
// Open the connection - physical connection is established here.
BOOL success = [thePrinterConn open];
NSError *error = nil;
// Send the data to printer as a byte array.
NSData* data = [ZPL dataUsingEncoding:NSUTF8StringEncoding];
success = success && [thePrinterConn write:data error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
if(success != YES || error != nil) {
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[errorAlert show];
}
});
// Close the connection to release resources.
[thePrinterConn close];
【问题讨论】:
标签: ios bluetooth zebra-printers