斑马 imz320 ZPL 蓝牙打印机 "ZSDK_API_ERROR_DOMAIN" - 代码:1 错误



我正在尝试使用 Zebra iMZ320 打印机在我的 iOS 应用程序上制作扩展程序。我遵循了斑马技术的开发人员指南。但是,我得到了一个关于SDK的错误。

这是我的代码:

- (IBAction)buttonPressed:(id)sender {
NSString *serialNumber = @"";
//Find the Zebra Bluetooth Accessory
EAAccessoryManager *sam = [EAAccessoryManager sharedAccessoryManager];
NSArray * connectedAccessories = [sam connectedAccessories];
for (EAAccessory *accessory in connectedAccessories) {
    if([accessory.protocolStrings indexOfObject:@"com.zebra.rawport"] != NSNotFound){
        serialNumber = accessory.serialNumber;
        break;
        //Note: This will find the first printer connected! If you have multiple Zebra printers connected, you should display a list to the user and have him select the one they wish to use
    }
}
// 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];
// This example prints "This is a ZPL test." near the top of the label.
NSString *zplData = @"^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
NSError *error = nil;
// Send the data to printer as a byte array.
success = success && [thePrinterConn write:[zplData dataUsingEncoding:NSUTF8StringEncoding] error:&error];
if (success != YES || error != nil) {
    UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [errorAlert show];
}

}

但是,当我尝试打印时,我从最后一个变量中得到一个错误NSError。它在写入功能中。

domain: "ZSDK_API_ERROR_DOMAIN" - code: 1

有人可以帮忙吗?提前谢谢。

我遇到了同样的问题,我的解决方案是使用 ZEBRA 提供的代码创建一个函数,并在用户按下的按钮上的不同线程中调用此函数。

-(IBAction)buttonPressed:(id)sender {
[NSThread detachNewThreadSelector:@selector(sendZplByBluetooth) toTarget:self withObject:nil];
}
-(void)sendZplByBluetooth{
//Zebra Code Here
}

意识到这一点非常昂贵,我希望它对您有所帮助。

尝试使用 zebra-toolkit。它将为您节省很多管理打印机和使用ZPL的麻烦。

相关内容

  • 没有找到相关文章

最新更新