简体   繁体   English

Zebra蓝牙打印机仅在调试器下工作

[英]Zebra bluetooth printer only working under debugger

I am printing to a QLn420 and it's working great under the debugger or when very small amounts of ZPL are passed to it but it fails when I run the app not under the debugger. 我正在打印到QLn420,它在调试器下运行良好,或者当有很少量的ZPL传递给它时,当我不在调试器下运行应用程序时,它运行失败。 The code is basically the same as Zebra's demo code ( https://km.zebra.com/kb/index?page=content&id=WH122&actp=LIST ) except the dispatch_async is performed earlier in the callstack. 该代码与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];

There is a delay setting for Bluetooth. 蓝牙有一个延迟设置。 Increase this to at least 100. Some phones are not capable of using the value set to 30. 将此值增加到至少100。某些电话无法使用设置为30的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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