Commit a87a2bec authored by lujunye's avatar lujunye

123123123

parent 159f046a
......@@ -451,15 +451,11 @@
E0D4166424483058008DCAB4 /* ChangePassViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0D4166224483058008DCAB4 /* ChangePassViewController.swift */; };
E0D4166524483058008DCAB4 /* ChangePassViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E0D4166324483058008DCAB4 /* ChangePassViewController.xib */; };
E0D46C5724503EC50087B564 /* TitleAndSelectCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = E0D46C5524503EC50087B564 /* TitleAndSelectCell.xib */; };
E0DA8AAA25E8F3D800425099 /* HLBLEManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8A9625E8F3D800425099 /* HLBLEManager.m */; };
E0DA8AAB25E8F3D800425099 /* SVRadialGradientLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8A9925E8F3D800425099 /* SVRadialGradientLayer.m */; };
E0DA8AAC25E8F3D800425099 /* SVProgressAnimatedView.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8A9C25E8F3D800425099 /* SVProgressAnimatedView.m */; };
E0DA8AAD25E8F3D800425099 /* SVProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8A9F25E8F3D800425099 /* SVProgressHUD.m */; };
E0DA8AAE25E8F3D800425099 /* SVIndefiniteAnimatedView.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8AA025E8F3D800425099 /* SVIndefiniteAnimatedView.m */; };
E0DA8AAF25E8F3D800425099 /* SVProgressHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = E0DA8AA125E8F3D800425099 /* SVProgressHUD.bundle */; };
E0DA8AB025E8F3D800425099 /* HLPrinter.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8AA425E8F3D800425099 /* HLPrinter.m */; };
E0DA8AB125E8F3D800425099 /* WKWebView+UIImage.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8AA525E8F3D800425099 /* WKWebView+UIImage.m */; };
E0DA8AB225E8F3D800425099 /* UIImage+Bitmap.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8AA825E8F3D800425099 /* UIImage+Bitmap.m */; };
E0DA8ACF25E8F4C000425099 /* BtViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E0DA8ACD25E8F4C000425099 /* BtViewController.m */; };
E0DA8AD025E8F4C000425099 /* BtViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E0DA8ACE25E8F4C000425099 /* BtViewController.xib */; };
E0DDCB0F244AD8C500DF54C7 /* DaiQueRenCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0DDCB0D244AD8C500DF54C7 /* DaiQueRenCell.swift */; };
......@@ -1276,9 +1272,6 @@
E0D4166224483058008DCAB4 /* ChangePassViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangePassViewController.swift; sourceTree = "<group>"; };
E0D4166324483058008DCAB4 /* ChangePassViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ChangePassViewController.xib; sourceTree = "<group>"; };
E0D46C5524503EC50087B564 /* TitleAndSelectCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TitleAndSelectCell.xib; sourceTree = "<group>"; };
E0DA8A9525E8F3D800425099 /* HLBLEConst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HLBLEConst.h; sourceTree = "<group>"; };
E0DA8A9625E8F3D800425099 /* HLBLEManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HLBLEManager.m; sourceTree = "<group>"; };
E0DA8A9725E8F3D800425099 /* HLBLEManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HLBLEManager.h; sourceTree = "<group>"; };
E0DA8A9925E8F3D800425099 /* SVRadialGradientLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVRadialGradientLayer.m; sourceTree = "<group>"; };
E0DA8A9A25E8F3D800425099 /* SVIndefiniteAnimatedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVIndefiniteAnimatedView.h; sourceTree = "<group>"; };
E0DA8A9B25E8F3D800425099 /* SVProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVProgressHUD.h; sourceTree = "<group>"; };
......@@ -1289,12 +1282,6 @@
E0DA8AA025E8F3D800425099 /* SVIndefiniteAnimatedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVIndefiniteAnimatedView.m; sourceTree = "<group>"; };
E0DA8AA125E8F3D800425099 /* SVProgressHUD.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = SVProgressHUD.bundle; sourceTree = "<group>"; };
E0DA8AA225E8F3D800425099 /* SVProgressAnimatedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVProgressAnimatedView.h; sourceTree = "<group>"; };
E0DA8AA425E8F3D800425099 /* HLPrinter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HLPrinter.m; sourceTree = "<group>"; };
E0DA8AA525E8F3D800425099 /* WKWebView+UIImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "WKWebView+UIImage.m"; sourceTree = "<group>"; };
E0DA8AA625E8F3D800425099 /* UIImage+Bitmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Bitmap.h"; sourceTree = "<group>"; };
E0DA8AA725E8F3D800425099 /* WKWebView+UIImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "WKWebView+UIImage.h"; sourceTree = "<group>"; };
E0DA8AA825E8F3D800425099 /* UIImage+Bitmap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Bitmap.m"; sourceTree = "<group>"; };
E0DA8AA925E8F3D800425099 /* HLPrinter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HLPrinter.h; sourceTree = "<group>"; };
E0DA8ACC25E8F4C000425099 /* BtViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BtViewController.h; sourceTree = "<group>"; };
E0DA8ACD25E8F4C000425099 /* BtViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BtViewController.m; sourceTree = "<group>"; };
E0DA8ACE25E8F4C000425099 /* BtViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BtViewController.xib; sourceTree = "<group>"; };
......@@ -2297,6 +2284,7 @@
E07412F52637AE700098006A /* GBDEMO */ = {
isa = PBXGroup;
children = (
E0DA8A9825E8F3D800425099 /* SVProgressHUD */,
E074130F2637AEBA0098006A /* ConnecterManager.h */,
E07413102637AEBA0098006A /* ConnecterManager.m */,
E07412F82637AE950098006A /* GSDK.a */,
......@@ -2621,7 +2609,6 @@
isa = PBXGroup;
children = (
E07412F52637AE700098006A /* GBDEMO */,
E0DA8A9325E8F3C900425099 /* HLPrinter */,
E09B3AB724B2FCAF00E3B238 /* ShareSDK */,
E09B3ACD24B2FCAF00E3B238 /* Required */,
);
......@@ -3003,26 +2990,6 @@
path = "修改密码";
sourceTree = "<group>";
};
E0DA8A9325E8F3C900425099 /* HLPrinter */ = {
isa = PBXGroup;
children = (
E0DA8A9425E8F3D800425099 /* HLBluetooth */,
E0DA8AA325E8F3D800425099 /* HLPrinter */,
E0DA8A9825E8F3D800425099 /* SVProgressHUD */,
);
path = HLPrinter;
sourceTree = "<group>";
};
E0DA8A9425E8F3D800425099 /* HLBluetooth */ = {
isa = PBXGroup;
children = (
E0DA8A9525E8F3D800425099 /* HLBLEConst.h */,
E0DA8A9625E8F3D800425099 /* HLBLEManager.m */,
E0DA8A9725E8F3D800425099 /* HLBLEManager.h */,
);
path = HLBluetooth;
sourceTree = "<group>";
};
E0DA8A9825E8F3D800425099 /* SVProgressHUD */ = {
isa = PBXGroup;
children = (
......@@ -3040,19 +3007,6 @@
path = SVProgressHUD;
sourceTree = "<group>";
};
E0DA8AA325E8F3D800425099 /* HLPrinter */ = {
isa = PBXGroup;
children = (
E0DA8AA725E8F3D800425099 /* WKWebView+UIImage.h */,
E0DA8AA525E8F3D800425099 /* WKWebView+UIImage.m */,
E0DA8AA625E8F3D800425099 /* UIImage+Bitmap.h */,
E0DA8AA825E8F3D800425099 /* UIImage+Bitmap.m */,
E0DA8AA925E8F3D800425099 /* HLPrinter.h */,
E0DA8AA425E8F3D800425099 /* HLPrinter.m */,
);
path = HLPrinter;
sourceTree = "<group>";
};
E0DDCB0B244AD84500DF54C7 /* 订单管理 */ = {
isa = PBXGroup;
children = (
......@@ -4367,7 +4321,6 @@
buildActionMask = 2147483647;
files = (
F956D5B7246A3255003FF510 /* OrderListModel.swift in Sources */,
E0DA8AB125E8F3D800425099 /* WKWebView+UIImage.m in Sources */,
E0A409C32463F31600CFF109 /* ShouZhiTongJiViewController.swift in Sources */,
F950FDE624518B9500C40530 /* FSCalendarAppearance.m in Sources */,
E0974D6C25C140A600E3C86B /* S_Y_Detail_Vc.swift in Sources */,
......@@ -4591,7 +4544,6 @@
E01614062601E78B00E55497 /* DZSH_Date_Cell.swift in Sources */,
E0B530882472917F00FFCC15 /* ShopWarehouseDetailModel.swift in Sources */,
F96E48A324CA79D4000AB8D4 /* WayBillAddressItemCell.swift in Sources */,
E0DA8AAA25E8F3D800425099 /* HLBLEManager.m in Sources */,
E0273DDD24551D4500B3FCAE /* OnlyLabelCell.swift in Sources */,
F950FDD724518B9500C40530 /* FSCalendarCollectionView.m in Sources */,
E0AFE970261D45AF00BD2A74 /* NonSelectPiCi_View.swift in Sources */,
......@@ -4682,7 +4634,6 @@
F9A4F24F24C9689600D1DD13 /* OtherDemandViewController.swift in Sources */,
F950FDD824518B9500C40530 /* FSCalendarDelegationProxy.m in Sources */,
E01EA1A0245A5D6B00F019D5 /* YunDanXiangQingViewController.swift in Sources */,
E0DA8AB025E8F3D800425099 /* HLPrinter.m in Sources */,
E051EBD724A1F0ED00892DA9 /* CGDCell.swift in Sources */,
F9697248248F88C70010D39B /* GeliAltetCodeView.swift in Sources */,
F93615DB2480B421004187F9 /* WorkInterface.swift in Sources */,
......@@ -4787,7 +4738,6 @@
E0B9461E24566B3100FBEC9A /* TitleAndTFAndBtnCell.swift in Sources */,
E042F74324529B7B00CDFA12 /* JiTuoWuXinXiView.swift in Sources */,
F933F6CC2452C68B00189561 /* WindowRootViewController.swift in Sources */,
E0DA8AB225E8F3D800425099 /* UIImage+Bitmap.m in Sources */,
F956D5AE246A2D9C003FF510 /* LMNTextLine.m in Sources */,
F9531F442465108800724BEE /* JXPhotoBrowserFadeAnimator.swift in Sources */,
E007B1DB248F8F57004D14CC /* PurchaseInterface.swift in Sources */,
......
......@@ -29,7 +29,7 @@
#import "SVProgressHUD.h"
#import "BtViewController.h"
#import "WKWebView+UIImage.h"
#import "BLEConnecter.h"
#import "EthernetConnecter.h"
......
//
// HLBLEConst.h
// HLBluetoothDemo
//
// Created by Harvey on 16/4/29.
// Copyright © 2016年 Halley. All rights reserved.
//
#ifndef HLBLEConst_h
#define HLBLEConst_h
typedef NS_ENUM(NSInteger, HLOptionStage) {
HLOptionStageConnection, //蓝牙连接阶段
HLOptionStageSeekServices, //搜索服务阶段
HLOptionStageSeekCharacteristics, //搜索特性阶段
HLOptionStageSeekdescriptors, //搜索描述信息阶段
};
#pragma mark ------------------- 通知的定义 --------------------------
/** 蓝牙状态改变的通知 */
#define kCentralManagerStateUpdateNoticiation @"kCentralManagerStateUpdateNoticiation"
#pragma mark ------------------- block的定义 --------------------------
/** 蓝牙状态改变的block */
typedef void(^HLStateUpdateBlock)(CBCentralManager *central);
/** 发现一个蓝牙外设的block */
typedef void(^HLDiscoverPeripheralBlock)(CBCentralManager *central, CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI);
/** 连接完成的block,失败error就不为nil */
typedef void(^HLConnectCompletionBlock)(CBPeripheral *peripheral, NSError *error);
/** 搜索到连接上的蓝牙外设的服务block */
typedef void(^HLDiscoveredServicesBlock)(CBPeripheral *peripheral, NSArray *services, NSError *error);
/** 搜索某个服务的子服务 的回调 */
typedef void(^HLDiscoveredIncludedServicesBlock)(CBPeripheral *peripheral,CBService *service, NSArray *includedServices, NSError *error);
/** 搜索到某个服务中的特性的block */
typedef void(^HLDiscoverCharacteristicsBlock)(CBPeripheral *peripheral, CBService *service, NSArray *characteristics, NSError *error);
/** 收到某个特性值更新的回调 */
typedef void(^HLNotifyCharacteristicBlock)(CBPeripheral *peripheral,CBCharacteristic *characteristic,NSError *error);
/** 查找到某个特性的描述 block */
typedef void(^HLDiscoverDescriptorsBlock)(CBPeripheral *peripheral,CBCharacteristic *characteristic,NSArray *descriptors, NSError *error);
/** 统一返回使用的block */
typedef void(^HLBLECompletionBlock)(HLOptionStage stage, CBPeripheral *peripheral,CBService *service, CBCharacteristic *character, NSError *error);
/** 获取特性中的值 */
typedef void(^HLValueForCharacteristicBlock)(CBCharacteristic *characteristic, NSData *value, NSError *error);
/** 获取描述中的值 */
typedef void(^HLValueForDescriptorBlock)(CBDescriptor *descriptor,NSData *data,NSError *error);
/** 往特性中写入数据的回调 */
typedef void(^HLWriteToCharacteristicBlock)(CBCharacteristic *characteristic, NSError *error);
/** 往描述中写入数据的回调 */
typedef void(^HLWriteToDescriptorBlock)(CBDescriptor *descriptor, NSError *error);
/** 获取蓝牙外设信号的回调 */
typedef void(^HLGetRSSIBlock)(CBPeripheral *peripheral,NSNumber *RSSI, NSError *error);
#endif /* HLBLEConst_h */
//
// HLBLEManager.h
// HLBluetoothDemo
//
// Created by Harvey on 16/4/27.
// Copyright © 2016年 Halley. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "HLBLEConst.h"
@interface HLBLEManager : NSObject
#pragma mark - properties
/** 蓝牙模块状态改变的回调 */
@property (copy, nonatomic) HLStateUpdateBlock stateUpdateBlock;
/** 发现一个蓝牙外设的回调 */
@property (copy, nonatomic) HLDiscoverPeripheralBlock discoverPeripheralBlcok;
/** 连接外设完成的回调 */
@property (copy, nonatomic) HLConnectCompletionBlock connectCompleteBlock;
/** 发现服务的回调 */
@property (copy, nonatomic) HLDiscoveredServicesBlock discoverServicesBlock;
/** 发现服务中的特性的回调 */
@property (copy, nonatomic) HLDiscoverCharacteristicsBlock discoverCharacteristicsBlock;
/** 特性值改变的回调 */
@property (copy, nonatomic) HLNotifyCharacteristicBlock notifyCharacteristicBlock;
/** 发现服务中的子服务的回调 */
@property (copy, nonatomic) HLDiscoveredIncludedServicesBlock discoverdIncludedServicesBlock;
/** 发现特性的描述的回调 */
@property (copy, nonatomic) HLDiscoverDescriptorsBlock discoverDescriptorsBlock;
/** 操作完成的统一回调 */
@property (copy, nonatomic) HLBLECompletionBlock completionBlock;
/** 获取特性值回调 */
@property (copy, nonatomic) HLValueForCharacteristicBlock valueForCharacteristicBlock;
/** 获取描述值的回调 */
@property (copy, nonatomic) HLValueForDescriptorBlock valueForDescriptorBlock;
/** 将数据写入特性中的回调 */
@property (copy, nonatomic) HLWriteToCharacteristicBlock writeToCharacteristicBlock;
/** 将数据写入描述中的回调*/
@property (copy, nonatomic) HLWriteToDescriptorBlock writeToDescriptorBlock;
/** 获取蓝牙外设信号强度的回调 */
@property (copy, nonatomic) HLGetRSSIBlock getRSSIBlock;
@property (strong, nonatomic, readonly) CBPeripheral *connectedPerpheral; /**< 当前连接的外设 */
/**
* 每次发送的最大数据长度,因为部分型号的蓝牙打印机一次写入数据过长,会导致打印乱码。
* iOS 9之后,会调用系统的API来获取特性能写入的最大数据长度。
* 但是iOS 9之前需要自己测试然后设置一个合适的值。默认值是146,我使用佳博58MB-III的限度。
* 所以,如果你打印乱码,你考虑将该值设置小一点再试试。
*/
@property (assign, nonatomic) NSInteger limitLength;
#pragma mark - method
+ (instancetype)sharedInstance;
/**
* 开始搜索蓝牙外设,每次在block中返回一个蓝牙外设信息
*
* @param uuids 服务的CBUUID
* @param option 其他可选参数
*/
- (void)scanForPeripheralsWithServiceUUIDs:(NSArray<CBUUID *> *)uuids options:(NSDictionary<NSString *, id> *)options;
/**
* 开始搜索蓝牙外设,每次在block中返回一个蓝牙外设信息
* 返回的block参数可参考CBCentralManager 的 centralManager:didDiscoverPeripheral:advertisementData:RSSI:
*
* @param uuids 服务的CBUUID
* @param option 其他可选参数
* @param discoverBlock 搜索到蓝牙外设后的回调
*/
- (void)scanForPeripheralsWithServiceUUIDs:(NSArray<CBUUID *> *)uuids options:(NSDictionary<NSString *, id> *)options didDiscoverPeripheral:(HLDiscoverPeripheralBlock)discoverBlock;
/**
* 连接某个蓝牙外设,并查询服务,特性,特性描述
*
* @param peripheral 要连接的蓝牙外设
* @param connectOptions 连接的配置参数
* @param stop 连接成功后是否停止搜索蓝牙外设
* @param serviceUUIDs 要搜索的服务UUID
* @param characteristicUUIDs 要搜索的特性UUID
* @param completionBlock 操作执行完的回调
*/
- (void)connectPeripheral:(CBPeripheral *)peripheral
connectOptions:(NSDictionary<NSString *,id> *)connectOptions
stopScanAfterConnected:(BOOL)stop
servicesOptions:(NSArray<CBUUID *> *)serviceUUIDs
characteristicsOptions:(NSArray<CBUUID *> *)characteristicUUIDs
completeBlock:(HLBLECompletionBlock)completionBlock;
/**
* 查找某个服务的子服务
*
* @param includedServiceUUIDs 要查找的子服务的UUIDs
* @param service 父服务
*/
- (void)discoverIncludedServices:(NSArray<CBUUID *> *)includedServiceUUIDs forService:(CBService *)service;
/**
* 读取某个特性的值
*
* @param characteristic 要读取的特性
*/
- (void)readValueForCharacteristic:(CBCharacteristic *)characteristic;
/**
* 读取某个特性的值
*
* @param characteristic 要读取的特性
* @param completionBlock 读取完后的回调
*/
- (void)readValueForCharacteristic:(CBCharacteristic *)characteristic completionBlock:(HLValueForCharacteristicBlock)completionBlock;
/**
* 往某个特性中写入数据
*
* @param data 写入的数据
* @param characteristic 特性对象
* @param type 写入类型
*/
- (void)writeValue:(NSData *)data forCharacteristic:(CBCharacteristic *)characteristic type:(CBCharacteristicWriteType)type;
/**
* 往某个特性中写入数据
*
* @param data 写入的数据
* @param characteristic 特性对象
* @param type 写入类型
* @param completionBlock 写入完成后的回调,只有type为CBCharacteristicWriteWithResponse时,才会回调
*/
- (void)writeValue:(NSData *)data forCharacteristic:(CBCharacteristic *)characteristic type:(CBCharacteristicWriteType)type completionBlock:(HLWriteToCharacteristicBlock)completionBlock;
/**
* 读取某特性的描述信息
*
* @param descriptor 描述对象
*/
- (void)readValueForDescriptor:(CBDescriptor *)descriptor;
/**
* 读取某特性的描述信息
*
* @param descriptor 描述对象
* @param completionBlock 读取结果返回时的回调
*/
- (void)readValueForDescriptor:(CBDescriptor *)descriptor completionBlock:(HLValueForDescriptorBlock)completionBlock;
/**
* 将数据写入特性的描述中
*
* @param data 数据
* @param descriptor 描述对象
*/
- (void)writeValue:(NSData *)data forDescriptor:(CBDescriptor *)descriptor;
/**
* 将数据写入特性的描述中
*
* @param data 数据
* @param descriptor 描述对象
* @param completionBlock 数据写入完成后的回调
*/
- (void)writeValue:(NSData *)data forDescriptor:(CBDescriptor *)descriptor completionBlock:(HLWriteToDescriptorBlock)completionBlock;
/**
* 获取某外设的信号
*
* @param completionBlock 获取信号完成后的回调
*/
- (void)readRSSICompletionBlock:(HLGetRSSIBlock)getRSSIBlock;
/**
* 停止扫描
*/
- (void)stopScan;
/**
* 断开蓝牙连接
*/
- (void)cancelPeripheralConnection;
@end
//
// HLBLEManager.m
// HLBluetoothDemo
//
// Created by Harvey on 16/4/27.
// Copyright © 2016年 Halley. All rights reserved.
//
#import "HLBLEManager.h"
// 发送数据时,需要分段的长度,部分打印机一次发送数据过长就会乱码,需要分段发送。这个长度值不同的打印机可能不一样,你需要调试设置一个合适的值(最好是偶数)
#define kLimitLength 146
@interface HLBLEManager ()<CBCentralManagerDelegate,CBPeripheralDelegate>
@property (strong, nonatomic) CBCentralManager *centralManager; /**< 中心管理器 */
@property (strong, nonatomic) CBPeripheral *connectedPerpheral; /**< 当前连接的外设 */
@property (strong, nonatomic) NSArray<CBUUID *> *serviceUUIDs; /**< 要查找服务的UUIDs */
@property (strong, nonatomic) NSArray<CBUUID *> *characteristicUUIDs; /**< 要查找特性的UUIDs */
@property (assign, nonatomic) BOOL stopScanAfterConnected; /**< 是否连接成功后停止扫描蓝牙设备 */
@property (assign, nonatomic) NSInteger writeCount; /**< 写入次数 */
@property (assign, nonatomic) NSInteger responseCount; /**< 返回次数 */
@end
static HLBLEManager *instance = nil;
@implementation HLBLEManager
+ (instancetype)sharedInstance
{
return [[self alloc] init];
}
- (instancetype)init {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [super init];
//蓝牙没打开时alert提示框
NSDictionary *options = @{CBCentralManagerOptionShowPowerAlertKey:@(YES)};
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue() options:options];
_limitLength = kLimitLength;
});
return instance;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [super allocWithZone:zone];
});
return instance;
}
- (void)scanForPeripheralsWithServiceUUIDs:(NSArray<CBUUID *> *)uuids options:(NSDictionary<NSString *, id> *)options
{
[_centralManager scanForPeripheralsWithServices:uuids options:options];
}
- (void)scanForPeripheralsWithServiceUUIDs:(NSArray<CBUUID *> *)uuids options:(NSDictionary<NSString *, id> *)options didDiscoverPeripheral:(HLDiscoverPeripheralBlock)discoverBlock
{
_discoverPeripheralBlcok = discoverBlock;
[_centralManager scanForPeripheralsWithServices:uuids options:options];
}
- (void)connectPeripheral:(CBPeripheral *)peripheral
connectOptions:(NSDictionary<NSString *,id> *)connectOptions
stopScanAfterConnected:(BOOL)stop
servicesOptions:(NSArray<CBUUID *> *)serviceUUIDs
characteristicsOptions:(NSArray<CBUUID *> *)characteristicUUIDs
completeBlock:(HLBLECompletionBlock)completionBlock;
{
//1.保存回调的block以及参数
_completionBlock = completionBlock;
_serviceUUIDs = serviceUUIDs;
_characteristicUUIDs = characteristicUUIDs;
_stopScanAfterConnected = stop;
//2.先取消之前连接的蓝牙外设
if (_connectedPerpheral) {
[_centralManager cancelPeripheralConnection:_connectedPerpheral];
}
//3.开始连接新的蓝牙外设
[_centralManager connectPeripheral:peripheral options:connectOptions];
//4.设置代理
peripheral.delegate = self;
}
- (void)discoverIncludedServices:(NSArray<CBUUID *> *)includedServiceUUIDs forService:(CBService *)service
{
[_connectedPerpheral discoverIncludedServices:includedServiceUUIDs forService:service];
}
- (void)stopScan
{
[_centralManager stopScan];
_discoverPeripheralBlcok = nil;
}
- (void)cancelPeripheralConnection
{
if (_connectedPerpheral) {
[_centralManager cancelPeripheralConnection:_connectedPerpheral];
}
}
- (void)readValueForCharacteristic:(CBCharacteristic *)characteristic
{
[_connectedPerpheral readValueForCharacteristic:characteristic];
}
- (void)readValueForCharacteristic:(CBCharacteristic *)characteristic completionBlock:(HLValueForCharacteristicBlock)completionBlock
{
_valueForCharacteristicBlock = completionBlock;
[self readValueForCharacteristic:characteristic];
}
- (void)writeValue:(NSData *)data forCharacteristic:(CBCharacteristic *)characteristic type:(CBCharacteristicWriteType)type
{
_writeCount = 0;
_responseCount = 0;
// iOS 9 以后,系统添加了这个API来获取特性能写入的最大长度
if ([_connectedPerpheral respondsToSelector:@selector(maximumWriteValueLengthForType:)]) {
_limitLength = [_connectedPerpheral maximumWriteValueLengthForType:type];
}
// 如果_limitLength 小于等于0,则表示不用分段发送
if (_limitLength <= 0) {
[_connectedPerpheral writeValue:data forCharacteristic:characteristic type:type];
_writeCount ++;
return;
}
if (data.length <= _limitLength) {
[_connectedPerpheral writeValue:data forCharacteristic:characteristic type:type];
_writeCount ++;
} else {
NSInteger index = 0;
for (index = 0; index < data.length - _limitLength; index += _limitLength) {
NSData *subData = [data subdataWithRange:NSMakeRange(index, _limitLength)];
[_connectedPerpheral writeValue:subData forCharacteristic:characteristic type:type];
_writeCount++;
}
NSData *leftData = [data subdataWithRange:NSMakeRange(index, data.length - index)];
if (leftData) {
[_connectedPerpheral writeValue:leftData forCharacteristic:characteristic type:type];
_writeCount++;
}
}
}
- (void)writeValue:(NSData *)data forCharacteristic:(CBCharacteristic *)characteristic type:(CBCharacteristicWriteType)type completionBlock:(HLWriteToCharacteristicBlock)completionBlock
{
_writeToCharacteristicBlock = completionBlock;
[self writeValue:data forCharacteristic:characteristic type:type];
}
- (void)readValueForDescriptor:(CBDescriptor *)descriptor
{
[_connectedPerpheral readValueForDescriptor:descriptor];
}
- (void)readValueForDescriptor:(CBDescriptor *)descriptor completionBlock:(HLValueForDescriptorBlock)completionBlock
{
_valueForDescriptorBlock = completionBlock;
[self readValueForDescriptor:descriptor];
}
- (void)writeValue:(NSData *)data forDescriptor:(CBDescriptor *)descriptor
{
[_connectedPerpheral writeValue:data forDescriptor:descriptor];
}
- (void)writeValue:(NSData *)data forDescriptor:(CBDescriptor *)descriptor completionBlock:(HLWriteToDescriptorBlock)completionBlock
{
_writeToDescriptorBlock = completionBlock;
[self writeValue:data forDescriptor:descriptor];
}
- (void)readRSSICompletionBlock:(HLGetRSSIBlock)getRSSIBlock
{
_getRSSIBlock = getRSSIBlock;
[_connectedPerpheral readRSSI];
}
#pragma mark - CBCentralManagerDelegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
[[NSNotificationCenter defaultCenter] postNotificationName:kCentralManagerStateUpdateNoticiation object:@{@"central":central}];
if (_stateUpdateBlock) {
_stateUpdateBlock(central);
}
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *, id> *)advertisementData RSSI:(NSNumber *)RSSI
{
if (_discoverPeripheralBlcok) {
_discoverPeripheralBlcok(central, peripheral, advertisementData, RSSI);
}
}
#pragma mark ---------------- 连接外设成功和失败的代理 ---------------
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
_connectedPerpheral = peripheral;
if (_stopScanAfterConnected) {
[_centralManager stopScan];
}
if (_discoverServicesBlock) {
_discoverServicesBlock(peripheral, peripheral.services,nil);
}
if (_completionBlock) {
_completionBlock(HLOptionStageConnection,peripheral,nil,nil,nil);
}
[peripheral discoverServices:_serviceUUIDs];
}
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error
{
if (_discoverServicesBlock) {
_discoverServicesBlock(peripheral, peripheral.services,error);
}
if (_completionBlock) {
_completionBlock(HLOptionStageConnection,peripheral,nil,nil,error);
}
}
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error
{
_connectedPerpheral = nil;
NSLog(@"断开连接了,断开连接了 %@",error);
}
#pragma mark ---------------- 发现服务的代理 -----------------
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(nullable NSError *)error
{
if (error) {
if (_completionBlock) {
_completionBlock(HLOptionStageSeekServices,peripheral,nil,nil,error);
}
return;
}
if (_completionBlock) {
_completionBlock(HLOptionStageSeekServices,peripheral,nil,nil,nil);
}
for (CBService *service in peripheral.services) {
[peripheral discoverCharacteristics:_characteristicUUIDs forService:service];
}
}
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverIncludedServicesForService:(CBService *)service error:(nullable NSError *)error
{
if (error) {
if (_discoverdIncludedServicesBlock) {
_discoverdIncludedServicesBlock(peripheral,service,nil,error);
}
return;
}
if (_discoverdIncludedServicesBlock) {
_discoverdIncludedServicesBlock(peripheral,service,service.includedServices,error);
}
}
#pragma mark ---------------- 服务特性的代理 --------------------
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(nullable NSError *)error
{
if (error) {
if (_completionBlock) {
_completionBlock(HLOptionStageSeekCharacteristics,peripheral,service,nil,error);
}
return;
}
if (_discoverCharacteristicsBlock) {
_discoverCharacteristicsBlock(peripheral,service,service.characteristics,nil);
}
if (_completionBlock) {
_completionBlock(HLOptionStageSeekCharacteristics,peripheral,service,nil,nil);
}
for (CBCharacteristic *character in service.characteristics) {
[peripheral discoverDescriptorsForCharacteristic:character];
[peripheral readValueForCharacteristic:character];
}
}
- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(nullable NSError *)error
{
if (error) {
if (_notifyCharacteristicBlock) {
_notifyCharacteristicBlock(peripheral,characteristic,error);
}
return;
}
if (_notifyCharacteristicBlock) {
_notifyCharacteristicBlock(peripheral,characteristic,nil);
}
}
// 读取特性中的值
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
if (error) {
if (_valueForCharacteristicBlock) {
_valueForCharacteristicBlock(characteristic,nil,error);
}
return;
}
//
NSData *data = characteristic.value;
// if (data.length > 0) {
// const unsigned char *hexBytesLight = [data bytes];
//
// NSString * battery = [NSString stringWithFormat:@"%02x", hexBytesLight[0]];
//
// NSLog(@"batteryInfo:%@",battery);
// }
if (_valueForCharacteristicBlock) {
_valueForCharacteristicBlock(characteristic,data,nil);
}
}
#pragma mark ---------------- 发现服务特性描述的代理 ------------------
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(CBCharacteristic *)characteristic error:(nullable NSError *)error
{
if (error) {
if (_completionBlock) {
_completionBlock(HLOptionStageSeekdescriptors,peripheral,nil,characteristic,error);
}
return;
}
if (_completionBlock) {
_completionBlock(HLOptionStageSeekdescriptors,peripheral,nil,characteristic,nil);
}
}
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForDescriptor:(CBDescriptor *)descriptor error:(nullable NSError *)error
{
if (error) {
if (_valueForDescriptorBlock) {
_valueForDescriptorBlock(descriptor,nil,error);
}
return;
}
NSData *data = descriptor.value;
if (_valueForDescriptorBlock) {
_valueForDescriptorBlock(descriptor,data,nil);
}
}
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForDescriptor:(CBDescriptor *)descriptor error:(nullable NSError *)error
{
if (error) {
if (_writeToDescriptorBlock) {
_writeToDescriptorBlock(descriptor, error);
}
return;
}
if (_writeToDescriptorBlock) {
_writeToDescriptorBlock(descriptor, nil);
}
}
#pragma mark ---------------- 写入数据的回调 --------------------
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(nullable NSError *)error
{
if (!_writeToCharacteristicBlock) {
return;
}
_responseCount ++;
if (_writeCount != _responseCount) {
return;
}
_writeToCharacteristicBlock(characteristic,error);
}
#pragma mark ---------------- 获取信号之后的回调 ------------------
# if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
- (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(nullable NSError *)error {
if (_getRSSIBlock) {
_getRSSIBlock(peripheral,peripheral.RSSI,error);
}
}
#else
- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(NSError *)error {
if (_getRSSIBlock) {
_getRSSIBlock(peripheral,RSSI,error);
}
}
#endif
@end
//
// HLPrinter.h
// HLBluetoothDemo
//
// Created by Harvey on 16/5/3.
// Copyright © 2016年 Halley. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "UIImage+Bitmap.h"
typedef NS_ENUM(NSInteger, HLPrinterStyle) {
HLPrinterStyleDefault,
HLPrinterStyleCustom
};
/** 文字对齐方式 */
typedef NS_ENUM(NSInteger, HLTextAlignment) {
HLTextAlignmentLeft = 0x00,
HLTextAlignmentCenter = 0x01,
HLTextAlignmentRight = 0x02
};
/** 字号 */
typedef NS_ENUM(NSInteger, HLFontSize) {
HLFontSizeTitleSmalle = 0x00,
HLFontSizeTitleMiddle = 0x11,
HLFontSizeTitleBig = 0x22
};
@interface HLPrinter : NSObject
/**
* 添加单行标题,默认字号是小号字体
*
* @param title 标题名称
* @param alignment 标题对齐方式
*/
- (void)appendText:(NSString *)text alignment:(HLTextAlignment)alignment;
/**
* 添加单行标题
*
* @param title 标题名称
* @param alignment 标题对齐方式
* @param fontSize 标题字号
*/
- (void)appendText:(NSString *)text alignment:(HLTextAlignment)alignment fontSize:(HLFontSize)fontSize;
/**
* 添加单行信息,左边名称(左对齐),右边实际值(右对齐),默认字号是小号。
* @param title 名称
* @param value 实际值
* 警告:因字号和字体与iOS中字体不一致,计算出来有误差,可以用[-appendTitle:value:valueOffset:]或[-appendTitle:value:valueOffset:fontSize:]
*/
- (void)appendTitle:(NSString *)title value:(NSString *)value;
/**
* 添加单行信息,左边名称(左对齐),右边实际值(右对齐)。
* @param title 名称
* @param value 实际值
* @param fontSize 字号大小
* 警告:因字号和字体与iOS中字体不一致,计算出来有误差,所以建议用在价格方面
*/
- (void)appendTitle:(NSString *)title value:(NSString *)value fontSize:(HLFontSize)fontSize;
/**
* 设置单行信息,左标题,右实际值
* @提醒 该方法的预览效果与实际效果误差较大,请以实际打印小票为准
*
* @param title 标题
* @param value 实际值
* @param offset 实际值偏移量
*/
- (void)appendTitle:(NSString *)title value:(NSString *)value valueOffset:(NSInteger)offset;
/**
* 设置单行信息,左标题,右实际值
* @提醒 该方法的预览效果与实际效果误差较大,请以实际打印小票为准
*
* @param title 标题
* @param value 实际值
* @param offset 实际值偏移量
* @param fontSize 字号
*/
- (void)appendTitle:(NSString *)title value:(NSString *)value valueOffset:(NSInteger)offset fontSize:(HLFontSize)fontSize;
/**
* 添加选购商品信息标题,一般是三列,名称、数量、单价
*
* @param LeftText 左标题
* @param middleText 中间标题
* @param rightText 右标题
*/
- (void)appendLeftText:(NSString *)left middleText:(NSString *)middle rightText:(NSString *)right isTitle:(BOOL)isTitle;
/**
* 添加图片,一般是添加二维码或者条形码
* ⚠️提醒:这种打印图片的方式,是自己生成图片,然后用位图打印
*
* @param image 图片
* @param alignment 图片对齐方式
* @param maxWidth 图片的最大宽度,如果图片过大,会等比缩放
*/
- (void)appendImage:(UIImage *)image alignment:(HLTextAlignment)alignment maxWidth:(CGFloat)maxWidth;
/**
* 添加条形码图片
* ⚠️提醒:这种打印条形码的方式,是自己生成条形码图片,然后用位图打印图片
*
* @param info 条形码中包含的信息,默认居中显示,最大宽度为300。如果大于300,会等比缩放。
*/
- (void)appendBarCodeWithInfo:(NSString *)info;
/**
* 添加条形码图片
* ⚠️提醒:这种打印条形码的方式,是自己生成条形码图片,然后用位图打印图片
*
* @param info 条形码中的信息
* @param alignment 图片对齐方式
* @param maxWidth 图片最大宽度
*/
- (void)appendBarCodeWithInfo:(NSString *)info alignment:(HLTextAlignment)alignment maxWidth:(CGFloat)maxWidth;
/**
* 添加二维码
* ✅推荐:这种方式使用的是打印机的指令生成二维码并打印机,所以比较推荐这种方式
*
* @param info 二维码中的信息
* @param size 二维码的大小 取值范围1 <= size <= 16
*/
- (void)appendQRCodeWithInfo:(NSString *)info size:(NSInteger)size;
/**
* 添加二维码
* ✅推荐:这种方式使用的是打印机的指令生成二维码并打印机,所以比较推荐这种方式
*
* @param info 二维码中的信息
* @param size 二维码大小,取值范围 1 <= size <= 16
* @param alignment 设置图片对齐方式
*/
- (void)appendQRCodeWithInfo:(NSString *)info size:(NSInteger)size alignment:(HLTextAlignment)alignment;
/**
* 添加二维码图片
* ⚠️提醒:这种打印条二维码的方式,是自己生成二维码图片,然后用位图打印图片
*
* @param info 二维码中的信息
*/
- (void)appendQRCodeWithInfo:(NSString *)info;
/**
* 添加二维码图片
* ⚠️提醒:这种打印条二维码的方式,是自己生成二维码图片,然后用位图打印图片
*
* @param info 二维码中的信息
* @param centerImage 二维码中间的图片
* @param alignment 对齐方式
* @param maxWidth 二维码的最大宽度
*/
- (void)appendQRCodeWithInfo:(NSString *)info centerImage:(UIImage *)centerImage alignment:(HLTextAlignment)alignment maxWidth:(CGFloat )maxWidth;
/**
* 添加一条分割线,like this:---------------------------
*/
- (void)appendSeperatorLine;
/**
* 添加底部信息
*
* @param footerInfo 不填默认为 谢谢惠顾,欢迎下次光临!
*/
- (void)appendFooter:(NSString *)footerInfo;
/**
添加自定义的data
@param data 自定义的data
*/
- (void)appendCustomData:(NSData *)data;
/**
* 获取最终的data
*
* @return 最终的data
*/
- (NSData *)getFinalData;
@end
//
// HLPrinter.m
// HLBluetoothDemo
//
// Created by Harvey on 16/5/3.
// Copyright © 2016年 Halley. All rights reserved.
//
#import "HLPrinter.h"
#define kHLMargin 20
#define kHLPadding 2
#define kHLPreviewWidth 320
@interface HLPrinter ()
/** 将要打印的排版后的数据 */
@property (strong, nonatomic) NSMutableData *printerData;
@end
@implementation HLPrinter
- (instancetype)init
{
self = [super init];
if (self) {
[self defaultSetting];
}
return self;
}
- (void)defaultSetting
{
_printerData = [[NSMutableData alloc] init];
// 1.初始化打印机
Byte initBytes[] = {0x1B,0x40};
[_printerData appendBytes:initBytes length:sizeof(initBytes)];
// 2.设置行间距为1/6英寸,约34个点
// 另一种设置行间距的方法看这个 @link{-setLineSpace:}
Byte lineSpace[] = {0x1B,0x32};
[_printerData appendBytes:lineSpace length:sizeof(lineSpace)];
// 3.设置字体:标准0x00,压缩0x01;
Byte fontBytes[] = {0x1B,0x4D,0x00};
[_printerData appendBytes:fontBytes length:sizeof(fontBytes)];
}
#pragma mark - -------------基本操作----------------
/**
* 换行
*/
- (void)appendNewLine
{
Byte nextRowBytes[] = {0x0A};
[_printerData appendBytes:nextRowBytes length:sizeof(nextRowBytes)];
}
/**
* 回车
*/
- (void)appendReturn
{
Byte returnBytes[] = {0x0D};
[_printerData appendBytes:returnBytes length:sizeof(returnBytes)];
}
/**
* 设置对齐方式
*
* @param alignment 对齐方式:居左、居中、居右
*/
- (void)setAlignment:(HLTextAlignment)alignment
{
Byte alignBytes[] = {0x1B,0x61,alignment};
[_printerData appendBytes:alignBytes length:sizeof(alignBytes)];
}
/**
* 设置字体大小
*
* @param fontSize 字号
*/
- (void)setFontSize:(HLFontSize)fontSize
{
Byte fontSizeBytes[] = {0x1D,0x21,fontSize};
[_printerData appendBytes:fontSizeBytes length:sizeof(fontSizeBytes)];
}
/**
* 添加文字,不换行
*
* @param text 文字内容
*/
- (void)setText:(NSString *)text
{
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSData *data = [text dataUsingEncoding:enc];
[_printerData appendData:data];
}
/**
* 添加文字,不换行
*
* @param text 文字内容
* @param maxChar 最多可以允许多少个字节,后面加...
*/
- (void)setText:(NSString *)text maxChar:(int)maxChar
{
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSData *data = [text dataUsingEncoding:enc];
if (data.length > maxChar) {
data = [data subdataWithRange:NSMakeRange(0, maxChar)];
text = [[NSString alloc] initWithData:data encoding:enc];
if (!text) {
data = [data subdataWithRange:NSMakeRange(0, maxChar - 1)];
text = [[NSString alloc] initWithData:data encoding:enc];
}
text = [text stringByAppendingString:@"..."];
}
[self setText:text];
}
/**
* 设置偏移文字
*
* @param text 文字
*/
- (void)setOffsetText:(NSString *)text
{
// 1.计算偏移量,因字体和字号不同,所以计算出来的宽度与实际宽度有误差(小字体与22字体计算值接近)
NSDictionary *dict = @{NSFontAttributeName:[UIFont systemFontOfSize:22.0]};
NSAttributedString *valueAttr = [[NSAttributedString alloc] initWithString:text attributes:dict];
int valueWidth = valueAttr.size.width;
// 2.设置偏移量
[self setOffset:368 - valueWidth];
// 3.设置文字
[self setText:text];
}
/**
* 设置偏移量
*
* @param offset 偏移量
*/
- (void)setOffset:(NSInteger)offset
{
NSInteger remainder = offset % 256;
NSInteger consult = offset / 256;
Byte spaceBytes2[] = {0x1B, 0x24, remainder, consult};
[_printerData appendBytes:spaceBytes2 length:sizeof(spaceBytes2)];
}
/**
* 设置行间距
*
* @param points 多少个点
*/
- (void)setLineSpace:(NSInteger)points
{
//最后一位,可选 0~255
Byte lineSpace[] = {0x1B,0x33,points};
[_printerData appendBytes:lineSpace length:sizeof(lineSpace)];
}
/**
* 设置二维码模块大小
*
* @param size 1<= size <= 16,二维码的宽高相等
*/
- (void)setQRCodeSize:(NSInteger)size
{
Byte QRSize [] = {0x1D,0x28,0x6B,0x03,0x00,0x31,0x43,size};
// Byte QRSize [] = {29,40,107,3,0,49,67,size};
[_printerData appendBytes:QRSize length:sizeof(QRSize)];
}
/**
* 设置二维码的纠错等级
*
* @param level 48 <= level <= 51
*/
- (void)setQRCodeErrorCorrection:(NSInteger)level
{
Byte levelBytes [] = {0x1D,0x28,0x6B,0x03,0x00,0x31,0x45,level};
// Byte levelBytes [] = {29,40,107,3,0,49,69,level};
[_printerData appendBytes:levelBytes length:sizeof(levelBytes)];
}
/**
* 将二维码数据存储到符号存储区
* [范围]: 4≤(pL+pH×256)≤7092 (0≤pL≤255,0≤pH≤27)
* cn=49
* fn=80
* m=48
* k=(pL+pH×256)-3, k就是数据的长度
*
* @param info 二维码数据
*/
- (void)setQRCodeInfo:(NSString *)info
{
NSInteger kLength = info.length + 3;
NSInteger pL = kLength % 256;
NSInteger pH = kLength / 256;
Byte dataBytes [] = {0x1D,0x28,0x6B,pL,pH,0x31,0x50,48};
// Byte dataBytes [] = {29,40,107,pL,pH,49,80,48};
[_printerData appendBytes:dataBytes length:sizeof(dataBytes)];
NSData *infoData = [info dataUsingEncoding:NSUTF8StringEncoding];
[_printerData appendData:infoData];
// [self setText:info];
}
/**
* 打印之前存储的二维码信息
*/
- (void)printStoredQRData
{
Byte printBytes [] = {0x1D,0x28,0x6B,0x03,0x00,0x31,0x51,48};
// Byte printBytes [] = {29,40,107,3,0,49,81,48};
[_printerData appendBytes:printBytes length:sizeof(printBytes)];
}
#pragma mark - ------------function method ----------------
#pragma mark 文字
- (void)appendText:(NSString *)text alignment:(HLTextAlignment)alignment
{
[self appendText:text alignment:alignment fontSize:HLFontSizeTitleSmalle];
}
- (void)appendText:(NSString *)text alignment:(HLTextAlignment)alignment fontSize:(HLFontSize)fontSize
{
// 1.文字对齐方式
[self setAlignment:alignment];
// 2.设置字号
[self setFontSize:fontSize];
// 3.设置标题内容
[self setText:text];
// 4.换行
[self appendNewLine];
if (fontSize != HLFontSizeTitleSmalle) {
[self appendNewLine];
}
}
- (void)appendTitle:(NSString *)title value:(NSString *)value
{
[self appendTitle:title value:value fontSize:HLFontSizeTitleSmalle];
}
- (void)appendTitle:(NSString *)title value:(NSString *)value fontSize:(HLFontSize)fontSize
{
// 1.设置对齐方式
[self setAlignment:HLTextAlignmentLeft];
// 2.设置字号
[self setFontSize:fontSize];
// 3.设置标题内容
[self setText:title];
// 4.设置实际值
[self setOffsetText:value];
// 5.换行
[self appendNewLine];
if (fontSize != HLFontSizeTitleSmalle) {
[self appendNewLine];
}
}
- (void)appendTitle:(NSString *)title value:(NSString *)value valueOffset:(NSInteger)offset
{
[self appendTitle:title value:value valueOffset:offset fontSize:HLFontSizeTitleSmalle];
}
- (void)appendTitle:(NSString *)title value:(NSString *)value valueOffset:(NSInteger)offset fontSize:(HLFontSize)fontSize
{
// 1.设置对齐方式
[self setAlignment:HLTextAlignmentLeft];
// 2.设置字号
[self setFontSize:fontSize];
// 3.设置标题内容
[self setText:title];
// 4.设置内容偏移量
[self setOffset:offset];
// 5.设置实际值
[self setText:value];
// 6.换行
[self appendNewLine];
if (fontSize != HLFontSizeTitleSmalle) {
[self appendNewLine];
}
}
- (void)appendLeftText:(NSString *)left middleText:(NSString *)middle rightText:(NSString *)right isTitle:(BOOL)isTitle
{
[self setAlignment:HLTextAlignmentLeft];
[self setFontSize:HLFontSizeTitleSmalle];
NSInteger offset = 0;
if (!isTitle) {
offset = 10;
}
if (left) {
[self setText:left maxChar:10];
}
if (middle) {
[self setOffset:150 + offset];
[self setText:middle];
}
if (right) {
[self setOffset:300 + offset];
[self setText:right];
}
[self appendNewLine];
}
#pragma mark 图片
- (void)appendImage:(UIImage *)image alignment:(HLTextAlignment)alignment maxWidth:(CGFloat)maxWidth
{
if (!image) {
return;
}
// 1.设置图片对齐方式
[self setAlignment:alignment];
// 2.设置图片
UIImage *newImage = [image imageWithscaleMaxWidth:maxWidth];
// newImage = [newImage blackAndWhiteImage];
NSData *imageData = [newImage bitmapData];
[_printerData appendData:imageData];
// 3.换行
[self appendNewLine];
// 4.打印图片后,恢复文字的行间距
Byte lineSpace[] = {0x1B,0x32};
[_printerData appendBytes:lineSpace length:sizeof(lineSpace)];
}
- (void)appendBarCodeWithInfo:(NSString *)info
{
[self appendBarCodeWithInfo:info alignment:HLTextAlignmentCenter maxWidth:300];
}
- (void)appendBarCodeWithInfo:(NSString *)info alignment:(HLTextAlignment)alignment maxWidth:(CGFloat)maxWidth
{
UIImage *barImage = [UIImage barCodeImageWithInfo:info];
[self appendImage:barImage alignment:alignment maxWidth:maxWidth];
}
- (void)appendQRCodeWithInfo:(NSString *)info size:(NSInteger)size
{
[self appendQRCodeWithInfo:info size:size alignment:HLTextAlignmentCenter];
}
- (void)appendQRCodeWithInfo:(NSString *)info size:(NSInteger)size alignment:(HLTextAlignment)alignment
{
[self setAlignment:alignment];
[self setQRCodeSize:size];
[self setQRCodeErrorCorrection:48];
[self setQRCodeInfo:info];
[self printStoredQRData];
[self appendNewLine];
}
- (void)appendQRCodeWithInfo:(NSString *)info
{
[self appendQRCodeWithInfo:info centerImage:nil alignment:HLTextAlignmentCenter maxWidth:250];
}
- (void)appendQRCodeWithInfo:(NSString *)info centerImage:(UIImage *)centerImage alignment:(HLTextAlignment)alignment maxWidth:(CGFloat )maxWidth
{
UIImage *QRImage = [UIImage qrCodeImageWithInfo:info centerImage:centerImage width:maxWidth];
[self appendImage:QRImage alignment:alignment maxWidth:maxWidth];
}
/**
添加自定义的data
@param data 自定义的data
*/
- (void)appendCustomData:(NSData *)data
{
if (data.length <= 0) {
return;
}
[_printerData appendData:data];
}
#pragma mark 其他
- (void)appendSeperatorLine
{
// 1.设置分割线居中
[self setAlignment:HLTextAlignmentCenter];
// 2.设置字号
[self setFontSize:HLFontSizeTitleSmalle];
// 3.添加分割线
NSString *line = @"- - - - - - - - - - - - - - - -";
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSData *data = [line dataUsingEncoding:enc];
[_printerData appendData:data];
// 4.换行
[self appendNewLine];
}
- (void)appendFooter:(NSString *)footerInfo
{
[self appendSeperatorLine];
if (!footerInfo) {
footerInfo = @"谢谢惠顾,欢迎下次光临!";
}
[self appendText:footerInfo alignment:HLTextAlignmentCenter];
}
- (NSData *)getFinalData
{
return _printerData;
}
@end
//
// UIImage+Bitmap.h
// HLBluetoothDemo
//
// Created by Harvey on 16/5/3.
// Copyright © 2016年 Halley. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger,BitPixels) {
BPAlpha = 0,
BPBlue = 1,
BPGreen = 2,
BPRed = 3
};
@interface UIImage (Bitmap)
/**
* 将图片转换为点阵图数据
*
* @return 转化后的点阵图数据
*/
- (NSData *)bitmapData;
/**
* 将图片绘制到绘图上下文中,并返回上下文
*
* @return
*/
//+ (CGContextRef)bitmapRGBA8ContextFromImage:(CGImageRef)image;
- (CGContextRef)bitmapRGBA8Context;
/**
* 缩放图片,会按照给定的最大宽度,等比缩放
*
* @param maxWidth 缩放后的最大宽度
*
* @return 返回缩放后的图片
*/
- (UIImage *)imageWithscaleMaxWidth:(CGFloat)maxWidth;
/**
* 将图片转换为黑白图片
*
* @return 黑白图片
*/
- (UIImage *)blackAndWhiteImage;
@end
#pragma mark - -----------制作二维码 条形码------------
@interface UIImage (QRCode)
/**
* 创建条形码
*
* @param info 字符串信息
*
* @return 条形码图片
*/
+ (UIImage *)barCodeImageWithInfo:(NSString *)info;
/**
* 创建二维码
*
* @param info 二维码内的信息
* @param image 二维码中心的logo图片
* @param width 二维码的宽度
*
* @return 二维码图片
*/
+ (UIImage *)qrCodeImageWithInfo:(NSString *)info centerImage:(UIImage *)image width:(CGFloat)width;
/**
* 将CIImage 放大显示,并转换为UIImage。
*
* @param image 原始CIImage
* @param size 最终尺寸的宽度
*
* @return UIImage
*/
+ (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat)size;
/**
* 将原图转变为背景色透明,图片为设置的颜色
*
* @param image 要改变的图片
* @param red red
* @param green green
* @param blue blue
*
* @return 返回修改后的图片
*/
+ (UIImage*)imageBgColorToTransparentWith:(UIImage*)image withRed:(CGFloat)red andGreen:(CGFloat)green andBlue:(CGFloat)blue;
@end
//
// UIImage+Bitmap.m
// HLBluetoothDemo
//
// Created by Harvey on 16/5/3.
// Copyright © 2016年 Halley. All rights reserved.
//
#import "UIImage+Bitmap.h"
#import <AVFoundation/AVFoundation.h>
@implementation UIImage (Bitmap)
//
- (NSData *)bitmapData
{
CGImageRef imageRef = self.CGImage;
// Create a bitmap context to draw the uiimage into
CGContextRef context = [self bitmapRGBA8Context];
if(!context) {
return nil;
}
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
CGRect rect = CGRectMake(0, 0, width, height);
// Draw image into the context to get the raw image data
CGContextDrawImage(context, rect, imageRef);
// Get a pointer to the data
uint32_t *bitmapData = (uint32_t *)CGBitmapContextGetData(context);
if(bitmapData) {
uint8_t *m_imageData = (uint8_t *) malloc(width * height/8 + 8*height/8);
memset(m_imageData, 0, width * height/8 + 8*height/8);
int result_index = 0;
for(int y = 0; (y + 24) < height; ) {
m_imageData[result_index++] = 27;
m_imageData[result_index++] = 51;
m_imageData[result_index++] = 0;
m_imageData[result_index++] = 27;
m_imageData[result_index++] = 42;
m_imageData[result_index++] = 33;
m_imageData[result_index++] = width%256;
m_imageData[result_index++] = width/256;
for(int x = 0; x < width; x++) {
int value = 0;
for (int temp_y = 0 ; temp_y < 8; ++temp_y)
{
uint8_t *rgbaPixel = (uint8_t *) &bitmapData[(y+temp_y) * width + x];
uint32_t gray = 0.3 * rgbaPixel[BPRed] + 0.59 * rgbaPixel[BPGreen] + 0.11 * rgbaPixel[BPBlue];
if (gray < 127)
{
value += 1<<(7-temp_y)&255;
}
}
m_imageData[result_index++] = value;
value = 0;
for (int temp_y = 8 ; temp_y < 16; ++temp_y)
{
uint8_t *rgbaPixel = (uint8_t *) &bitmapData[(y+temp_y) * width + x];
uint32_t gray = 0.3 * rgbaPixel[BPRed] + 0.59 * rgbaPixel[BPGreen] + 0.11 * rgbaPixel[BPBlue];
if (gray < 127)
{
value += 1<<(7-temp_y%8)&255;
}
}
m_imageData[result_index++] = value;
value = 0;
for (int temp_y = 16 ; temp_y < 24; ++temp_y)
{
uint8_t *rgbaPixel = (uint8_t *) &bitmapData[(y+temp_y) * width + x];
uint32_t gray = 0.3 * rgbaPixel[BPRed] + 0.59 * rgbaPixel[BPGreen] + 0.11 * rgbaPixel[BPBlue];
if (gray < 127)
{
value += 1<<(7-temp_y%8)&255;
}
}
m_imageData[result_index++] = value;
}
m_imageData[result_index++] = 13;
m_imageData[result_index++] = 10;
y += 24;
}
NSMutableData *data = [[NSMutableData alloc] initWithCapacity:0];
[data appendBytes:m_imageData length:result_index];
free(bitmapData);
return data;
}
NSLog(@"Error getting bitmap pixel data\n");
CGContextRelease(context);
return nil ;
}
- (CGContextRef)bitmapRGBA8Context
{
CGImageRef imageRef = self.CGImage;
if (!imageRef) {
return NULL;
}
CGContextRef context = NULL;
CGColorSpaceRef colorSpace;
uint32_t *bitmapData;
size_t bitsPerPixel = 32;
size_t bitsPerComponent = 8;
size_t bytesPerPixel = bitsPerPixel / bitsPerComponent;
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
size_t bytesPerRow = width * bytesPerPixel;
size_t bufferLength = bytesPerRow * height;
colorSpace = CGColorSpaceCreateDeviceRGB();
if(!colorSpace) {
NSLog(@"Error allocating color space RGB\n");
return NULL;
}
// Allocate memory for image data
bitmapData = (uint32_t *)malloc(bufferLength);
if(!bitmapData) {
NSLog(@"Error allocating memory for bitmap\n");
CGColorSpaceRelease(colorSpace);
return NULL;
}
//Create bitmap context
context = CGBitmapContextCreate(bitmapData,
width,
height,
bitsPerComponent,
bytesPerRow,
colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast); // RGBA
if(!context) {
free(bitmapData);
NSLog(@"Bitmap context not created");
}
CGColorSpaceRelease(colorSpace);
return context;
}
- (UIImage *)imageWithscaleMaxWidth:(CGFloat)maxWidth
{
CGFloat width = self.size.width;
if (width > maxWidth)
{
CGFloat height = self.size.height;
CGFloat maxHeight = maxWidth * height / width;
CGSize size = CGSizeMake(maxWidth, maxHeight);
UIGraphicsBeginImageContext(size);
[self drawInRect:CGRectMake(0, 0, maxWidth, maxHeight)];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
return self;
}
- (UIImage *)blackAndWhiteImage
{
// CGSize size = self.size;
CIImage *beginImage = [CIImage imageWithCGImage:self.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIColorMonochrome"
keysAndValues:kCIInputImageKey,beginImage,kCIInputColorKey,[CIColor colorWithCGColor:[UIColor blackColor].CGColor],nil];
CIImage *outputImage = [filter outputImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef imageRef = [context createCGImage:outputImage fromRect:outputImage.extent];
UIImage *newImage = [UIImage imageWithCGImage:imageRef];
// UIImage *newImage = [UIImage createNonInterpolatedUIImageFormCIImage:outputImage withSize:size.width];
return newImage;
}
@end
@implementation UIImage (QRCode)
+ (UIImage *)barCodeImageWithInfo:(NSString *)info
{
// 创建条形码
CIFilter *filter = [CIFilter filterWithName:@"CICode128BarcodeGenerator"];
// 恢复滤镜的默认属性
[filter setDefaults];
// 将字符串转换成NSData
NSData *data = [info dataUsingEncoding:NSUTF8StringEncoding];
// 通过KVO设置滤镜inputMessage数据
[filter setValue:data forKey:@"inputMessage"];
// 获得滤镜输出的图像
CIImage *outputImage = [filter outputImage];
// 将CIImage转换成UIImage,并放大显示
UIImage *image =[self createNonInterpolatedUIImageFormCIImage:outputImage withSize:300];
return image;
}
+ (UIImage *)qrCodeImageWithInfo:(NSString *)info centerImage:(UIImage *)centerImage width:(CGFloat)width
{
if (!info) {
return nil;
}
NSData *strData = [info dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
//创建二维码滤镜
CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[qrFilter setValue:strData forKey:@"inputMessage"];
[qrFilter setValue:@"H" forKey:@"inputCorrectionLevel"];
CIImage *qrImage = qrFilter.outputImage;
UIImage *codeImage = [UIImage createNonInterpolatedUIImageFormCIImage:qrImage withSize:width];
//二维码rect
CGRect rect = CGRectMake(0, 0, codeImage.size.width, codeImage.size.height);
UIGraphicsBeginImageContext(rect.size);
[codeImage drawInRect:rect];
//定制logo
if (centerImage) {
//icon尺寸,UIBezierPath
CGSize logoSize = CGSizeMake(rect.size.width*0.2, rect.size.height*0.2);
CGFloat x = CGRectGetMidX(rect) - logoSize.width*0.5;
CGFloat y = CGRectGetMidY(rect) - logoSize.height*0.5;
CGRect logoFrame = CGRectMake(x, y, logoSize.width, logoSize.height);
[[UIBezierPath bezierPathWithRoundedRect:logoFrame cornerRadius:10] addClip];
[centerImage drawInRect:logoFrame];
}
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
+ (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat)size
{
CGRect extent = CGRectIntegral(image.extent);
CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
// 创建bitmap;
size_t width = CGRectGetWidth(extent) * scale;
size_t height = CGRectGetHeight(extent) * scale;
CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
CGContextScaleCTM(bitmapRef, scale, scale);
CGContextDrawImage(bitmapRef, extent, bitmapImage);
// 保存bitmap到图片
CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
CGContextRelease(bitmapRef);
CGImageRelease(bitmapImage);
return [UIImage imageWithCGImage:scaledImage];
}
void ProviderReleaseData (void *info, const void *data, size_t size){
free((void*)data);
}
+ (UIImage*)imageBgColorToTransparentWith:(UIImage*)image withRed:(CGFloat)red andGreen:(CGFloat)green andBlue:(CGFloat)blue{
const int imageWidth = image.size.width;
const int imageHeight = image.size.height;
size_t bytesPerRow = imageWidth * 4;
uint32_t* rgbImageBuf = (uint32_t*)malloc(bytesPerRow * imageHeight);
// create context
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(rgbImageBuf, imageWidth, imageHeight, 8, bytesPerRow, colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
CGContextDrawImage(context, CGRectMake(0, 0, imageWidth, imageHeight), image.CGImage);
// traverse pixe
int pixelNum = imageWidth * imageHeight;
uint32_t* pCurPtr = rgbImageBuf;
for (int i = 0; i < pixelNum; i++, pCurPtr++){
if ((*pCurPtr & 0xFFFFFF00) < 0x99999900){
// change color
uint8_t* ptr = (uint8_t*)pCurPtr;
ptr[3] = red; //0~255
ptr[2] = green;
ptr[1] = blue;
}else{
uint8_t* ptr = (uint8_t*)pCurPtr;
ptr[0] = 0;
}
}
// context to image
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, rgbImageBuf, bytesPerRow * imageHeight, ProviderReleaseData);
CGImageRef imageRef = CGImageCreate(imageWidth, imageHeight, 8, 32, bytesPerRow, colorSpace,
kCGImageAlphaLast | kCGBitmapByteOrder32Little, dataProvider,
NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(dataProvider);
UIImage* resultUIImage = [UIImage imageWithCGImage:imageRef];
// release
CGImageRelease(imageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return resultUIImage;
}
@end
//
// HLBluetoothDemo
//
// Created by Harvey on 16/5/13.
// Copyright © 2016年 Halley. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
@interface WKWebView (UIImage)
/**
* 获取当前加载的网页的截图
*
* @return
*/
- (UIImage *)imageForWebView;
@end
//
// HLBluetoothDemo
//
// Created by Harvey on 16/5/13.
// Copyright © 2016年 Halley. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "WKWebView+UIImage.h"
@implementation WKWebView (UIImage)
/**
* 获取当前加载的网页的截图
* 获取当前WebView的size,然后一屏一屏的截图后,再拼接成一张完整的图片
*
* @return
*/
- (UIImage *)imageForWebView
{
// 1.获取WebView的宽高
CGSize boundsSize = self.bounds.size;
CGFloat boundsWidth = boundsSize.width;
CGFloat boundsHeight = boundsSize.height;
// 2.获取contentSize
CGSize contentSize = self.scrollView.contentSize;
CGFloat contentHeight = contentSize.height;
// 3.保存原始偏移量,便于截图后复位
CGPoint offset = self.scrollView.contentOffset;
// 4.设置最初的偏移量为(0,0);
[self.scrollView setContentOffset:CGPointMake(0, 0)];
NSMutableArray *images = [NSMutableArray array];
while (contentHeight > 0) {
// 5.获取CGContext 5.获取CGContext
UIGraphicsBeginImageContextWithOptions(boundsSize, NO, 0.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 6.渲染要截取的区域
[self.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// 7.截取的图片保存起来
[images addObject:image];
CGFloat offsetY = self.scrollView.contentOffset.y;
[self.scrollView setContentOffset:CGPointMake(0, offsetY + boundsHeight)];
contentHeight -= boundsHeight;
}
// 8 webView 恢复到之前的显示区域
[self.scrollView setContentOffset:offset];
CGFloat scale = [UIScreen mainScreen].scale;
CGSize imageSize = CGSizeMake(contentSize.width * scale,
contentSize.height * scale);
// 9.根据设备的分辨率重新绘制、拼接成完整清晰图片
UIGraphicsBeginImageContext(imageSize);
[images enumerateObjectsUsingBlock:^(UIImage *image, NSUInteger idx, BOOL *stop) {
[image drawInRect:CGRectMake(0,
scale * boundsHeight * idx,
scale * boundsWidth,
scale * boundsHeight)];
}];
UIImage *fullImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return fullImage;
}
@end
......@@ -7,10 +7,7 @@
//
#import "BtViewController.h"
#import "HLBLEManager.h"
#import "SVProgressHUD.h"
#import "HLPrinter.h"
#import "WKWebView+UIImage.h"
#import "Bt_Cell.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment