第一步:
下載SDK;
步驟:在漢印官網(wǎng)下載中心(http://cn.hprt.com/XiaZai/HM-A300),下載iOS 版SDK(圖1,圖2.);
圖1:

圖2:

第二步:
集成SDK;
步驟:解壓下載的 iOS-SDK文件-->把SDK拉進文件(圖3.).
圖3:

第三步:
根據(jù)開發(fā)文檔開發(fā);
步驟:用到的開發(fā)文檔(圖4.)
圖4:

第四步:
添加依賴庫CoreBluetooth.framework;
步驟:圖5.
圖5:

第五步:
添加可能用到的類;
步驟:打開Demo(圖6.)-->可以搜索需要的類(圖7.)-->把需要的類拉進項目(圖8.).
圖6:

圖7:

圖8:

第六步:
編寫代碼;
1.在打印頁面引入頭文件;
#import "PTScaleImage.h"
#import?#import "Template.h"
#import "PTTestESC.h"
#import "PTLabelAppend.h"
2.添加鏈接藍牙打印機的方法;
#define mark - 藍牙鏈接打印機- (void)autoConnectBluetoothWithPrinter {?? ?? ? [[PTDispatcher share] scanBluetooth];?
? [[PTDispatcher share] whenFindBluetoothAll:^(NSDictionary *printerDic) {?? ? ? ?? ? ?
? for (PTPrinter *printer in printerDic.allValues) {?? ? ? ? ? ?? ? ? ? ?
? if ([printer.name isEqualToString:@"HM-M35"]) {?? ? ? ? ? ? ? ?? ? ? ? ? ? ?
? printer.model = @"QNG-LBO-I4R-HOV";?? ? ? ? ? ? ? ?? ? ? ? ? ? ? ?
[[PTDispatcher share] stopScanBluetooth];?? ? ? ? ? ? ? ?? ? ? ? ? ? ?
? [[PTDispatcher share] connectPrinter:printer];?? ? ? ? ? ? ? ?? ? ? ? ? ?
? ? [[PTDispatcher share] whenConnectSuccess:^{? ? ? ? ? ?
? ? ? ? NSLog(@"-Success- /wzw/ ");?? ? ? ? ? ? ? ? ? ?? ? ? ? ?
? ? ? }];? ? ? ?
? ? }? ? ? ?
}? ?
}];?? ?
}
3.判斷打印機狀態(tài);
- (void) CPCL_printer {?? ??
? [[PTDispatcher share] whenUpdatePrintState:^(PTPrintState state) {? ? }];? ?
[[PTDispatcher share] whenReceiveData:^(NSData *data) {? ? }];?? ??
? if ([[PTDispatcher share] printerConnected] == nil) {? ? ? ?
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"打印機未鏈接" message:@"" preferredStyle:UIAlertControllerStyleAlert];? ? ? ?
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}];? ? ?
? [alertController addAction:okAction];? ? ? ?
[self presentViewController:alertController animated:YES completion:nil];? ?
} else {?? ? ? ?? ? ?
? [self printWX_CPCL]; ?//打印
? }??
?}
4.打印方法
- (void) printWX_CPCL {?? ?? ?
PTCommandCPCL *cmd = [[PTCommandCPCL alloc] init];? ?
//紙張類型?
? [cmd cpclLabelWithOffset:0 hRes:200 vRes:200 height:1259 quantity:1];
//? ? [cmd cpclSetBold:1];?? ?? ?
//圖片? ?
UIImage *logo = [UIImage imageNamed:@"printerImg.jpg"];?
? NSData *bmpData = [PTBitmap getImageData:logo.CGImage mode:PTBitmapModeBinary compress:PTBitmapCompressModeNone];?
? [cmd cpclCompressedGraphicsWithImageWidth:logo.size.width imageHeight:logo.size.height x:10 y:10 bitmapData:bmpData];? ?
//加粗?
? [cmd cpclSetBold:1];?
? //標題 字體?
? [cmd cpclTextWithRotate:0 font:4 fontSize:0 x:250 y:40 text:@"wx ? ? ? 快遞包裹"];? ?
//不加粗? ?
[cmd cpclSetBold:0];? ?
//橫線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y? ?
[cmd cpclLineWithXPos:0 yPos:112 xEnd:600 yEnd:112 thickness:2];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:16 y:150 text:@"收"];?
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:16 y:190 text:@"件"];?? ??
? [cmd cpclTextWithRotate:0 font:4 fontSize:0 x:86 y:130 text:@"韋小寶 ? ? ? ? 15689069090"];? ? [cmd cpclTextWithRotate:0 font:4 fontSize:0 x:86 y:170 text:@"廣州市白云區(qū)白云大道北白云堡"];?
? [cmd cpclTextWithRotate:0 font:4 fontSize:0 x:86 y:210 text:@"社區(qū)111號"];? ?
//橫線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y? ?
[cmd cpclLineWithXPos:0 yPos:250 xEnd:600 yEnd:250 thickness:2];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:16 y:288 text:@"寄"];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:16 y:328 text:@"件"];?? ??
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:268 text:@"貂蟬 ? ? ? ? 13889069090"];?
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:308 text:@"深圳市福田區(qū)福田大道北啦啦"];?
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:348 text:@"社區(qū)111號"];?? ??
? //豎線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y? ?
[cmd cpclLineWithXPos:60 yPos:112 xEnd:60 yEnd:383 thickness:2];?
? //橫線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y? ?
[cmd cpclLineWithXPos:0 yPos:383 xEnd:600 yEnd:383 thickness:2];??
?//? ? [cmd cpclSetBold:0];? ?
//條形碼? ?
[cmd cpclBarcode:@"128" width:2 ratio:2 height:80 x:100 y:395 barcode:@"123456789"];
? ? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:180 y:490 text:@"123456789"];?? ?? ?
//橫線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y?
? [cmd cpclLineWithXPos:0 yPos:530 xEnd:600 yEnd:530 thickness:2];? ?
//? ?
[cmd cpclTextWithRotate:0 font:55 fontSize:0 x:16 y:540 text:@"快件送到收件人地址,經(jīng)收"];?
? [cmd cpclTextWithRotate:0 font:55 fontSize:0 x:16 y:560 text:@"件人或收件人/寄件人允許的"];?
? [cmd cpclTextWithRotate:0 font:55 fontSize:0 x:16 y:580 text:@"代人簽字,視為送達,您的"];?
? [cmd cpclTextWithRotate:0 font:55 fontSize:0 x:16 y:600 text:@"簽字代表您已驗收此包裹,"];?
? [cmd cpclTextWithRotate:0 font:55 fontSize:0 x:16 y:620 text:@"并已確認商品信息無誤,包"];? ?
[cmd cpclTextWithRotate:0 font:55 fontSize:0 x:16 y:640 text:@"裝完好、沒有劃痕、破損等"];? ?
[cmd cpclTextWithRotate:0 font:55 fontSize:0 x:16 y:660 text:@"表面質(zhì)量問題。"];?? ?? ?
//豎線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y? ?
[cmd cpclLineWithXPos:230 yPos:530 xEnd:230 yEnd:678 thickness:2];? ?
[cmd cpclTextWithRotate:0 font:3 fontSize:0 x:242 y:550 text:@"簽收人:"];? ?
[cmd cpclTextWithRotate:0 font:3 fontSize:0 x:242 y:650 text:@"時間:"];? ?
//豎線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y?
? [cmd cpclLineWithXPos:400 yPos:530 xEnd:400 yEnd:678 thickness:2];? ?
//二維碼? ?
[cmd cpclBarcodeQRcodeWithXPos:430 yPos:560 model:2 unitWidth:5];?
? [cmd cpclBarcodeQRcodeData:@"wan" config:@"MA"];//http://www.1wangxian.com/download.html? ?
[cmd cpclBarcodeQRcodeEnd];?? ??
? //橫線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y?
? [cmd cpclLineWithXPos:0 yPos:680 xEnd:600 yEnd:680 thickness:2];? ?
//圖片?
? [cmd cpclCompressedGraphicsWithImageWidth:logo.size.width imageHeight:logo.size.height x:10 y:720 bitmapData:bmpData];? ?
//條形碼?
? [cmd cpclBarcode:@"128" width:2 ratio:2 height:80 x:230 y:690 barcode:@"123456789"];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:350 y:790 text:@"123456789"];? ?
//橫線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y? ?
[cmd cpclLineWithXPos:0 yPos:830 xEnd:600 yEnd:830 thickness:2];?
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:16 y:868 text:@"收"];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:16 y:908 text:@"件"];?? ??
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:868 text:@"韋小寶 ? ? ? ? 15689069090"];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:908 text:@"廣州市白云區(qū)白云大道北白云堡"];?
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:948 text:@"社區(qū)111號"];? ?
//橫線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y?
? [cmd cpclLineWithXPos:0 yPos:990 xEnd:600 yEnd:990 thickness:2];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:16 y:1028 text:@"寄"];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:16 y:1068 text:@"件"];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:1008 text:@"貂蟬 ? ? ? ? 13889069090"];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:1048 text:@"深圳市福田區(qū)福田大道北啦啦"];?
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:86 y:1088 text:@"社區(qū)111號"];?? ??
? //豎線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y?
? [cmd cpclLineWithXPos:60 yPos:830 xEnd:60 yEnd:1125 thickness:2];?
? //橫線? ? ? ? ? ? ? 起點x ? ? y? ? ? 終點x? ? ? ? y?
? [cmd cpclLineWithXPos:0 yPos:1125 xEnd:600 yEnd:1125 thickness:2];?? ??? ?
? ? [cmd cpclTextWithRotate:0 font:4 fontSize:0 x:130 y:1170 text:@"重量: 6 (kg)"];? ?
[cmd cpclTextWithRotate:0 font:8 fontSize:0 x:400 y:1138 text:@"已驗視"];?
? [cmd cpclTextWithRotate:0 font:3 fontSize:0 x:400 y:1165 text:@"東區(qū)大宗"];?
? [cmd cpclTextWithRotate:0 font:3 fontSize:0 x:400 y:1192 text:@"姚璐"];?
? [cmd cpclTextWithRotate:0 font:8 fontSize:0 x:400 y:1219 text:@"已安檢"];?? ??
? [cmd cpclForm]; // 定位到下一標簽,標簽紙模式下啟用該指令?
? [cmd cpclPrint];? //打印?? ?
? ? [[PTDispatcher share] sendData:cmd.cmdData];
}
完成...(可以打印了.)