我正在使用for循环连接用于打开现金抽屉的多台打印机,但不适用于多台打印机。 打开现金抽屉后,我也想打印收据
我的代码在这里:
NSMutableArray *SelectedPrinter=[[NSUSERDEFAULTS valueForKey:@"SelectedPrinter"] mutableCopy];
for (int i=0; i<SelectedPrinter.count; i++)
{
[self printdataWithTarget:[[SelectedPrinter objectAtIndex:i] valueForKey:@"modelName"] withDeviceName:[[SelectedPrinter objectAtIndex:i] valueForKey:@"portName"]];
}
(void)printdataWithTarget:(NSString*)target withDeviceName:(NSString *)deviceName
{
[[MPOSPrinter sharedManager] disconnectPrinter];
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void)
{
[[MPOSPrinter sharedManager] disconnectPrinter];
if ([[MPOSPrinter sharedManager] initializePrinter:deviceName])
{
if (![[MPOSPrinter sharedManager] connectPrinterWithPort:target])
{
[MBProgressHUD hideHUDForView:[APPDELEGATE window] animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:[APPDELEGATE window] animated:YES];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
});
//showAlert(@"",@"Please ensure your device is connected with the Printer and you have selected this hardware from the settings menu.");
}
else
{
if ([[MPOSPrinter sharedManager] isPrintable:[[[MPOSPrinter sharedManager] printer] getStatus]])
{
[[[MPOSPrinter sharedManager] printer] addTextAlign:1];
[[[MPOSPrinter sharedManager] printer] addText:@""];
[[[MPOSPrinter sharedManager] printer] forceStopSound:0];
[[[MPOSPrinter sharedManager] printer] setReceiveEventDelegate:self];
[[[MPOSPrinter sharedManager] printer] addPulse:EPOS2_DRAWER_HIGH time:EPOS2_PULSE_100];
[[[MPOSPrinter sharedManager] printer] sendData:EPOS2_PARAM_DEFAULT];
}
else{
[MBProgressHUD hideHUDForView:[APPDELEGATE window] animated:YES];
}
}
}
else
{
[MBProgressHUD hideHUDForView:[APPDELEGATE window] animated:YES];
NSLog(@"Not Initialize");
}
});
}