美文网首页蓝牙知识
iOS蓝牙打印小票

iOS蓝牙打印小票

作者: 就是很随意哦 | 来源:发表于2017-12-21 17:08 被阅读51次

最近搞了个蓝牙打印小票的小东西,先上效果


IMG_0132(20171221-162648).jpg

数据格式 json:

{
    "ShopName":"XX宜山路店",
    "ShopPhone":"电话:021-64701557",
    "ShopInfos":[
                 "公司名称:XX光学科技(上海)有限公司 地址:徐汇区XX路700号",
                 "会员名称:13482089514TQC",
                 "订单编号:KALJLAJGLAIJGLAKGJJLAGJ",
                 "销售时间:2016-04-27 10:01:50",
                 "配镜顾问:吴志鹏",
                 "顾客姓名:王小姐",
                 "顾客电话:12345678909",
                 "备注:KALJLAJGLAIJGLAKGJJLAGJ"
                ],
    "GoodsAttributes":[
                       "名称",
                       "规格",
                       "批号",
                       "有效期",
                       "单价",
                       "数量",
                       "小计"
                       ],
    "GoodsProducts":[
                     "XX时尚光学眼镜Ke1820-F01 亮深灰  \n              490.00 1 ¥490.00",
                     "XX镜布灰色  \n              490.00 1 ¥490.00",
                     "XX非球面树脂镜片(薄) 左眼 光度:-1.50 散光:无 轴位:无 瞳距:60  \n              490.00 1 ¥490.00",
                     "XX非球面树脂镜片(薄) 右眼 光度:-1.50 散光:无 轴位:无 瞳距:60, \n              490.00 1 ¥490.00"
    ],
    "PayInfos":[
                "支付宝支付:    ¥490.00",
                "  金额合计:    ¥490.00",
                "  促销抵扣:    ¥0.00",
                "  实收合计:    ¥490.00",
                "  欠款金额:    ¥0.00"
    ],
    "ServesInfo":"XX、XX品牌镜架2年质保 1.限非人为原因导致的镜架质量问题 2.按【XX装配标准 GB13511.1-2011】执行",
    "QRCodeURL":"www.XX.com",
    "FootTitle":"扫码获取发票,欢迎再次惠顾!"
}

使用:

- (HLPrinter *)getPrinterWith:(id)Object
{
    HLPrinter *printer = [[HLPrinter alloc] init];
    //读取本地的json数据
    NSData *JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"app" ofType:@"json"]];
    NSDictionary *datadic = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil];

    //店铺信息
    NSArray * ShopInfos = datadic[@"ShopInfos"];
    [printer appendImage:[UIImage imageNamed:@"ico180"] alignment:HLTextAlignmentCenter maxWidth:300];//图片大小
    NSString *title = datadic[@"ShopName"];
    NSString *str1 = datadic[@"ShopPhone"];
    [printer appendText:title alignment:HLTextAlignmentCenter fontSize:HLFontSizeTitleMiddle];
    [printer appendText:str1 alignment:HLTextAlignmentCenter];

    for (int i= 0; i<ShopInfos.count; i++) {
        [printer appendText:ShopInfos[i] alignment:HLTextAlignmentLeft];
    }
    [printer appendNewLine];//换行,打印空白行

    //商品规格信息
    NSArray * GoodsAttributes = datadic[@"GoodsAttributes"];
    [printer appendLeftTextArray:GoodsAttributes];
    //商品信息
    NSArray * GoodsProducts = datadic[@"GoodsProducts"];

    for (NSString *goodsInfo in GoodsProducts) {
        [printer appendText:goodsInfo alignment:HLTextAlignmentLeft];
    }
    [printer appendNewLine];

    //支付信息
    NSArray * PayInfos = datadic[@"PayInfos"];

    for (int i=0; i< PayInfos.count; i++){
        [printer appendText:PayInfos[i] alignment:HLTextAlignmentLeft offSet:200];//偏移量
    }
    [printer appendSeperatorLine];

    [printer appendText:datadic[@"ServesInfo"] alignment:HLTextAlignmentLeft];
    [printer appendSeperatorLine];

//    [printer appendQRCodeWithInfo:@""]// 不推荐,文本太长的话,二维码底部会显示不全
    [printer appendQRCodeWithInfo:datadic[@"QRCodeURL"] size:6 alignment:HLTextAlignmentCenter]; //size 调整二维码大小

    [printer appendNewLine];
    [printer appendText:datadic[@"FootTitle"] alignment:HLTextAlignmentCenter];
    [printer appendNewLine];

    return printer;
}

- (void)printDataText:(id)obj
{
    HLPrinter *printer = [self getPrinterWith:obj];

    NSData *mainData = [printer getFinalData];
    [[SEPrinterManager sharedInstance] sendPrintData:mainData completion:^(CBPeripheral *connectPerpheral, BOOL completion, NSString *error) {
        NSLog(@"写入结:%d---错误:%@",completion,error);
    }];

}

话不多说上Demo:GitHub地址

相关文章

  • 打印机

    iOS开发之蓝牙/Socket链接小票打印机(一)iOS开发之蓝牙/Socket链接小票打印机(二) iOS so...

  • iOS 蓝牙打印小票

    前言: 最近做了款蓝牙打印的功能,包含蓝牙自动连接,蓝牙搜索,连接之后进行打印。总结了下知识点,写了一个简单的De...

  • iOS蓝牙打印小票

    最近搞了个蓝牙打印小票的小东西,先上效果 数据格式 json: 使用: 话不多说上Demo:GitHub地址

  • CoreBluetooth

    iOS-BLE蓝牙开发持续更新 - 简书 蓝牙打印小票 一个第三方 IOS BLE4.0蓝牙和外设连接和收发数据的...

  • iOS蓝牙4.0打印小票功能的实现

    公司业务有涉及到订单模块,客户需要连接蓝牙打印机打印订单小票。所以本文就记录一下iOS蓝牙打印的相关知识以及实际开...

  • iOS开发 蓝牙打印小票

    要求:手机通过蓝牙连接蓝牙打印机,在手机上点击‘打印’,打印机就打印出小票(小票就跟送外卖的那种)。 设备:BT5...

  • iOS CoreBluetooth 的使用讲解

    最近研究了iOS下连接蓝牙打印机,实现打印购物小票的功能,对iOS中BLE 4.0的使用有了一定的了解,这里记录一...

  • 蓝牙打印小票

    //蓝牙搜索的类 @interface QueryPrinterViewController (){ UIT...

  • iOS 蓝牙打印小票命令汇总

    在SaaS App中有很多地方需要通过连接蓝牙打印机打印结算及订单小票,而且在结算的时候使用打印机的的频率比较高,...

  • iOS Bluetooth 打印小票(一)

    在iOS app中连接蓝牙打印机打印商品小票,在没有电脑只有手机的情况下,感觉非常实用,而且最近经常最近公司正好也...

网友评论

    本文标题:iOS蓝牙打印小票

    本文链接:https://www.haomeiwen.com/subject/ekiawxtx.html