漢印A300系列-藍牙打印機(iOS開發(fā))

第一步:

下載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];

}

完成...(可以打印了.)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1 CALayer IOS SDK詳解之CALayer(一) http://doc.okbase.net/Hell...
    Kevin_Junbaozi閱讀 5,338評論 3 23
  • --繪圖與濾鏡全面解析 概述 在iOS中可以很容易的開發(fā)出絢麗的界面效果,一方面得益于成功系統(tǒng)的設(shè)計,另一方面得益...
    韓七夏閱讀 2,975評論 2 10
  • 嘗試和大家一起探討以下問題: view繪制渲染機制和runloop什么關(guān)系? 所謂的列表卡頓,到底是什么原因引發(fā)的...
    朽木自雕也閱讀 3,174評論 4 9
  • 不知道是否有人和我一樣,總覺得生活不是那么真實,總覺得生活的劇本早已經(jīng)寫好,而我們不過是冥冥之中按照它的劇本進行...
    鹿維晴閱讀 372評論 0 0
  • 我永遠不會忘記,被自己當成朋友、天天沒心沒肺在一起廝混的“朋友”誣蔑,那種滋味。 高三下學(xué)期我們必須要住校,我沒有...
    櫻花蝸牛閱讀 1,056評論 0 2

友情鏈接更多精彩內(nèi)容