0
我正在打印到QLn420,它在調試器下工作良好,或者只有極少量的ZPL傳遞給它,但當我運行不在調試器下的應用程序時,它失敗。代碼與Zebra的演示代碼(https://km.zebra.com/kb/index?page=content&id=WH122&actp=LIST)基本相同,不同之處在於dispatch_async在調用堆棧中較早執行。Zebra藍牙打印機只能在調試器下工作
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];