LDKPrinter
/*!
* @discussion Simple description of the current printer class
*/
- (NSString*) aboutDescription;
/*!
* @discussion Determines whether printer supports printing images
* @return TRUE if the printer supports printing images, FALSE otherwise
*/
- (BOOL) supportsImages;
/*!
* @discussion Initialization method for external printer, requires serial number
* @warning This method must be called before anything can be done to the printer object
* @param serialNumber The serial number of the external device
*/
-(void) bindToPrinterWithSerialNumber:(NSString*) serialNumber;
/*!
* @discussion Closes the connection the printer
* @warning This method should be called after printing to prevent memory leaks
*/
-(void) unbind;
/*!
* @discussion Standardized method for all implementing classes to update delegate
* @param printerStatus An LDKPrinterStatus indicating current status of printer
* @param message The string representing the printer status
*/
-(void) updatePrinterStatus:(LDKPrinterStatus) status withMessage:(NSString*) message;
/*!
* @discussion Asynchronous method for printing an LDMItem
* @param item The LDMItem to print (expected to be a Cart with line items)
* @param config The PrintConfig item
* @param completion Asychronous block that is called after receipt finishes printing
*/
-(void) printReceiptForItem:(LDMItem*) item withConfig:(LDKPrinterConfig*) config andCompletionHandler: (void (^)(BOOL success, NSString* message)) completion;
Writing Your Own Printer Manager
Liquid Core API comes with LDKPrinterManagerViewController to easily select existing printers and print carts. However, if there is a desire to write your own, this can be done some guidelines.
- Use LDKPrinterFactory to retrieve the correct LDKPrinter implementation
- Implement the printer delegate
- This is used to update UI Labels to check printer status
- Bind the printer
self.printer = [LDKPrinterFactory printerForProfile:self.printerProfile];
self.printer.delegate = self;
[self.printer bindToPrinterWithSerialNumber:self.defaultPrinterSerialNumber];
After the printing has been binded, you can proceed to print the item of interest:
[self.printer printReceiptForItem:self.cart withConfig:config andCompletionHandler:^(BOOL success, NSString *message) {
[self enableDoneButton];
if (!success)
{
[[[UIAlertView alloc] initWithTitle:@"Alert" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
}];
The following code is an easy way to obtain all external accessories connected to the current iOS device:
EAAccessoryManager *manager = [EAAccessoryManager sharedAccessoryManager];
self.connectedDevices = [NSMutableArray arrayWithArray:manager.connectedAccessories];
Remember to call unbind when printing has completed, or else memory leaks may occur.
[self.printer unbind];
The actual printing code is executed on a priority queue, defined below:
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
The completion handler is called by the main thread when it is done, so there is never any need to dispatch a new thread to update the UI.