Commit 37b07214 authored by lujunye's avatar lujunye

安静了;阿酸豆角啊打发时间;拉水电费;浪费

parent e1d93a92
......@@ -40,13 +40,13 @@ import ESTabBarController_swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,loginDelegate,UITabBarControllerDelegate, JPUSHRegisterDelegate{
var blueToothVC:ConnectViewController!
var blueToothVC:UIViewController!
var window:UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// 启动图,调整展示时间为3秒
Thread .sleep(forTimeInterval: 2.0)
blueToothVC = ConnectViewController()
blueToothVC = UIViewController()
let UserToken = UserDefaults.standard.value(forKey: "user_token")
if UserToken == nil {
......
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "chenggong.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "chenggong@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "chenggong@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -26,10 +26,8 @@
#import "JZLocationConverter.h"
#import "CBController.h"
#import "DeviceInfo.h"
#import "TscCommand.h"
#import "BLKWrite.h"
#import "EscCommand.h"
#import "ConnectViewController.h"
#import "HLBLEManager.h"
#import "SVProgressHUD.h"
#endif /* Bridge_Header_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
//
// 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
This diff is collapsed.
//
// 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
//
// UIWebView+UIImage.h
// HLBluetoothDemo
//
// Created by Harvey on 16/5/13.
// Copyright © 2016年 Halley. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIWebView (UIImage)
/**
* 获取当前加载的网页的截图
*
* @return
*/
- (UIImage *)imageForWebView;
@end
//
// UIWebView+UIImage.m
// HLBluetoothDemo
//
// Created by Harvey on 16/5/13.
// Copyright © 2016年 Halley. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "UIWebView+UIImage.h"
@implementation UIWebView (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
//
// SVIndefiniteAnimatedView.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2016 Guillaume Campagna. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SVIndefiniteAnimatedView : UIView
@property (nonatomic, assign) CGFloat strokeThickness;
@property (nonatomic, assign) CGFloat radius;
@property (nonatomic, strong) UIColor *strokeColor;
@end
//
// SVIndefiniteAnimatedView.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2016 Guillaume Campagna. All rights reserved.
//
#import "SVIndefiniteAnimatedView.h"
#import "SVProgressHUD.h"
@interface SVIndefiniteAnimatedView ()
@property (nonatomic, strong) CAShapeLayer *indefiniteAnimatedLayer;
@end
@implementation SVIndefiniteAnimatedView
- (void)willMoveToSuperview:(UIView*)newSuperview {
if (newSuperview) {
[self layoutAnimatedLayer];
} else {
[_indefiniteAnimatedLayer removeFromSuperlayer];
_indefiniteAnimatedLayer = nil;
}
}
- (void)layoutAnimatedLayer {
CALayer *layer = self.indefiniteAnimatedLayer;
[self.layer addSublayer:layer];
CGFloat widthDiff = CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds);
CGFloat heightDiff = CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds);
layer.position = CGPointMake(CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds) / 2 - widthDiff / 2, CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds) / 2 - heightDiff / 2);
}
- (CAShapeLayer*)indefiniteAnimatedLayer {
if(!_indefiniteAnimatedLayer) {
CGPoint arcCenter = CGPointMake(self.radius+self.strokeThickness/2+5, self.radius+self.strokeThickness/2+5);
UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:arcCenter radius:self.radius startAngle:(CGFloat) (M_PI*3/2) endAngle:(CGFloat) (M_PI/2+M_PI*5) clockwise:YES];
_indefiniteAnimatedLayer = [CAShapeLayer layer];
_indefiniteAnimatedLayer.contentsScale = [[UIScreen mainScreen] scale];
_indefiniteAnimatedLayer.frame = CGRectMake(0.0f, 0.0f, arcCenter.x*2, arcCenter.y*2);
_indefiniteAnimatedLayer.fillColor = [UIColor clearColor].CGColor;
_indefiniteAnimatedLayer.strokeColor = self.strokeColor.CGColor;
_indefiniteAnimatedLayer.lineWidth = self.strokeThickness;
_indefiniteAnimatedLayer.lineCap = kCALineCapRound;
_indefiniteAnimatedLayer.lineJoin = kCALineJoinBevel;
_indefiniteAnimatedLayer.path = smoothedPath.CGPath;
CALayer *maskLayer = [CALayer layer];
NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]];
NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"];
NSBundle *imageBundle = [NSBundle bundleWithURL:url];
NSString *path = [imageBundle pathForResource:@"angle-mask" ofType:@"png"];
maskLayer.contents = (__bridge id)[[UIImage imageWithContentsOfFile:path] CGImage];
maskLayer.frame = _indefiniteAnimatedLayer.bounds;
_indefiniteAnimatedLayer.mask = maskLayer;
NSTimeInterval animationDuration = 1;
CAMediaTimingFunction *linearCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.fromValue = (id) 0;
animation.toValue = @(M_PI*2);
animation.duration = animationDuration;
animation.timingFunction = linearCurve;
animation.removedOnCompletion = NO;
animation.repeatCount = INFINITY;
animation.fillMode = kCAFillModeForwards;
animation.autoreverses = NO;
[_indefiniteAnimatedLayer.mask addAnimation:animation forKey:@"rotate"];
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.duration = animationDuration;
animationGroup.repeatCount = INFINITY;
animationGroup.removedOnCompletion = NO;
animationGroup.timingFunction = linearCurve;
CABasicAnimation *strokeStartAnimation = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
strokeStartAnimation.fromValue = @0.015;
strokeStartAnimation.toValue = @0.515;
CABasicAnimation *strokeEndAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
strokeEndAnimation.fromValue = @0.485;
strokeEndAnimation.toValue = @0.985;
animationGroup.animations = @[strokeStartAnimation, strokeEndAnimation];
[_indefiniteAnimatedLayer addAnimation:animationGroup forKey:@"progress"];
}
return _indefiniteAnimatedLayer;
}
- (void)setFrame:(CGRect)frame {
if(!CGRectEqualToRect(frame, super.frame)) {
[super setFrame:frame];
if(self.superview) {
[self layoutAnimatedLayer];
}
}
}
- (void)setRadius:(CGFloat)radius {
if(radius != _radius) {
_radius = radius;
[_indefiniteAnimatedLayer removeFromSuperlayer];
_indefiniteAnimatedLayer = nil;
if(self.superview) {
[self layoutAnimatedLayer];
}
}
}
- (void)setStrokeColor:(UIColor*)strokeColor {
_strokeColor = strokeColor;
_indefiniteAnimatedLayer.strokeColor = strokeColor.CGColor;
}
- (void)setStrokeThickness:(CGFloat)strokeThickness {
_strokeThickness = strokeThickness;
_indefiniteAnimatedLayer.lineWidth = _strokeThickness;
}
- (CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake((self.radius+self.strokeThickness/2+5)*2, (self.radius+self.strokeThickness/2+5)*2);
}
@end
//
// SVProgressAnimatedView.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2016 Tobias Tiemerding. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SVProgressAnimatedView : UIView
@property (nonatomic, assign) CGFloat radius;
@property (nonatomic, assign) CGFloat strokeThickness;
@property (nonatomic, strong) UIColor *strokeColor;
@property (nonatomic, assign) CGFloat strokeEnd;
@end
//
// SVProgressAnimatedView.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2016 Tobias Tiemerding. All rights reserved.
//
#import "SVProgressAnimatedView.h"
@interface SVProgressAnimatedView ()
@property (nonatomic, strong) CAShapeLayer *ringAnimatedLayer;
@end
@implementation SVProgressAnimatedView
- (void)willMoveToSuperview:(UIView*)newSuperview {
if (newSuperview) {
[self layoutAnimatedLayer];
} else {
[_ringAnimatedLayer removeFromSuperlayer];
_ringAnimatedLayer = nil;
}
}
- (void)layoutAnimatedLayer {
CALayer *layer = self.ringAnimatedLayer;
[self.layer addSublayer:layer];
CGFloat widthDiff = CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds);
CGFloat heightDiff = CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds);
layer.position = CGPointMake(CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds) / 2 - widthDiff / 2, CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds) / 2 - heightDiff / 2);
}
- (CAShapeLayer*)ringAnimatedLayer {
if(!_ringAnimatedLayer) {
CGPoint arcCenter = CGPointMake(self.radius+self.strokeThickness/2+5, self.radius+self.strokeThickness/2+5);
UIBezierPath* smoothedPath = [UIBezierPath bezierPathWithArcCenter:arcCenter radius:self.radius startAngle:(CGFloat)-M_PI_2 endAngle:(CGFloat) (M_PI + M_PI_2) clockwise:YES];
_ringAnimatedLayer = [CAShapeLayer layer];
_ringAnimatedLayer.contentsScale = [[UIScreen mainScreen] scale];
_ringAnimatedLayer.frame = CGRectMake(0.0f, 0.0f, arcCenter.x*2, arcCenter.y*2);
_ringAnimatedLayer.fillColor = [UIColor clearColor].CGColor;
_ringAnimatedLayer.strokeColor = self.strokeColor.CGColor;
_ringAnimatedLayer.lineWidth = self.strokeThickness;
_ringAnimatedLayer.lineCap = kCALineCapRound;
_ringAnimatedLayer.lineJoin = kCALineJoinBevel;
_ringAnimatedLayer.path = smoothedPath.CGPath;
}
return _ringAnimatedLayer;
}
- (void)setFrame:(CGRect)frame {
if(!CGRectEqualToRect(frame, super.frame)) {
[super setFrame:frame];
if(self.superview) {
[self layoutAnimatedLayer];
}
}
}
- (void)setRadius:(CGFloat)radius {
if(radius != _radius) {
_radius = radius;
[_ringAnimatedLayer removeFromSuperlayer];
_ringAnimatedLayer = nil;
if(self.superview) {
[self layoutAnimatedLayer];
}
}
}
- (void)setStrokeColor:(UIColor*)strokeColor {
_strokeColor = strokeColor;
_ringAnimatedLayer.strokeColor = strokeColor.CGColor;
}
- (void)setStrokeThickness:(CGFloat)strokeThickness {
_strokeThickness = strokeThickness;
_ringAnimatedLayer.lineWidth = _strokeThickness;
}
- (void)setStrokeEnd:(CGFloat)strokeEnd {
_strokeEnd = strokeEnd;
_ringAnimatedLayer.strokeEnd = _strokeEnd;
}
- (CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake((self.radius+self.strokeThickness/2+5)*2, (self.radius+self.strokeThickness/2+5)*2);
}
@end
//
// Prefix header for all source files of the 'SVProgressHUD' target in the 'SVProgressHUD' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif
//
// SVProgressHUD.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2011-2016 Sam Vermette and contributors. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AvailabilityMacros.h>
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 70000
#define UI_APPEARANCE_SELECTOR
#endif
extern NSString * const SVProgressHUDDidReceiveTouchEventNotification;
extern NSString * const SVProgressHUDDidTouchDownInsideNotification;
extern NSString * const SVProgressHUDWillDisappearNotification;
extern NSString * const SVProgressHUDDidDisappearNotification;
extern NSString * const SVProgressHUDWillAppearNotification;
extern NSString * const SVProgressHUDDidAppearNotification;
extern NSString * const SVProgressHUDStatusUserInfoKey;
typedef NS_ENUM(NSInteger, SVProgressHUDStyle) {
SVProgressHUDStyleLight, // default style, white HUD with black text, HUD background will be blurred on iOS 8 and above
SVProgressHUDStyleDark, // black HUD and white text, HUD background will be blurred on iOS 8 and above
SVProgressHUDStyleCustom // uses the fore- and background color properties
};
typedef NS_ENUM(NSUInteger, SVProgressHUDMaskType) {
SVProgressHUDMaskTypeNone = 1, // default mask type, allow user interactions while HUD is displayed
SVProgressHUDMaskTypeClear, // don't allow user interactions
SVProgressHUDMaskTypeBlack, // don't allow user interactions and dim the UI in the back of the HUD, as on iOS 7 and above
SVProgressHUDMaskTypeGradient, // don't allow user interactions and dim the UI with a a-la UIAlertView background gradient, as on iOS 6
SVProgressHUDMaskTypeCustom // don't allow user interactions and dim the UI in the back of the HUD with a custom color
};
typedef NS_ENUM(NSUInteger, SVProgressHUDAnimationType) {
SVProgressHUDAnimationTypeFlat, // default animation type, custom flat animation (indefinite animated ring)
SVProgressHUDAnimationTypeNative // iOS native UIActivityIndicatorView
};
@interface SVProgressHUD : UIView
#pragma mark - Customization
@property (assign, nonatomic) SVProgressHUDStyle defaultStyle UI_APPEARANCE_SELECTOR; // default is SVProgressHUDStyleLight
@property (assign, nonatomic) SVProgressHUDMaskType defaultMaskType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDMaskTypeNone
@property (assign, nonatomic) SVProgressHUDAnimationType defaultAnimationType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDAnimationTypeFlat
@property (assign, nonatomic) CGSize minimumSize UI_APPEARANCE_SELECTOR; // default is CGSizeZero, can be used to avoid resizing for a larger message
@property (assign, nonatomic) CGFloat ringThickness UI_APPEARANCE_SELECTOR; // default is 2 pt
@property (assign, nonatomic) CGFloat ringRadius UI_APPEARANCE_SELECTOR; // default is 18 pt
@property (assign, nonatomic) CGFloat ringNoTextRadius UI_APPEARANCE_SELECTOR; // default is 24 pt
@property (assign, nonatomic) CGFloat cornerRadius UI_APPEARANCE_SELECTOR; // default is 14 pt
@property (strong, nonatomic) UIFont *font UI_APPEARANCE_SELECTOR; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
@property (strong, nonatomic) UIColor *backgroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor whiteColor]
@property (strong, nonatomic) UIColor *foregroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor blackColor]
@property (strong, nonatomic) UIColor *backgroundLayerColor UI_APPEARANCE_SELECTOR; // default is [UIColor colorWithWhite:0 alpha:0.4]
@property (strong, nonatomic) UIImage *infoImage UI_APPEARANCE_SELECTOR; // default is the bundled info image provided by Freepik
@property (strong, nonatomic) UIImage *successImage UI_APPEARANCE_SELECTOR; // default is the bundled success image provided by Freepik
@property (strong, nonatomic) UIImage *errorImage UI_APPEARANCE_SELECTOR; // default is the bundled error image provided by Freepik
@property (strong, nonatomic) UIView *viewForExtension UI_APPEARANCE_SELECTOR; // default is nil, only used if #define SV_APP_EXTENSIONS is set
@property (assign, nonatomic) NSTimeInterval minimumDismissTimeInterval; // default is 5.0 seconds
@property (assign, nonatomic) UIOffset offsetFromCenter UI_APPEARANCE_SELECTOR; // default is 0, 0
@property (assign, nonatomic) NSTimeInterval fadeInAnimationDuration; // default is 0.15
@property (assign, nonatomic) NSTimeInterval fadeOutAnimationDuration; // default is 0.15
+ (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat
+ (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing for a larger message
+ (void)setRingThickness:(CGFloat)ringThickness; // default is 2 pt
+ (void)setRingRadius:(CGFloat)radius; // default is 18 pt
+ (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt
+ (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt
+ (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
+ (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundLayerColor:(UIColor*)color; // default is [UIColor colorWithWhite:0 alpha:0.5], only used for SVProgressHUDMaskTypeBlack
+ (void)setInfoImage:(UIImage*)image; // default is the bundled info image provided by Freepik
+ (void)setSuccessImage:(UIImage*)image; // default is the bundled success image provided by Freepik
+ (void)setErrorImage:(UIImage*)image; // default is the bundled error image provided by Freepik
+ (void)setViewForExtension:(UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
#pragma mark - Show Methods
+ (void)show;
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use show and setDefaultMaskType: instead.")));
+ (void)showWithStatus:(NSString*)status;
+ (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showWithStatus: and setDefaultMaskType: instead.")));
+ (void)showProgress:(float)progress;
+ (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress: and setDefaultMaskType: instead.")));
+ (void)showProgress:(float)progress status:(NSString*)status;
+ (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress:status: and setDefaultMaskType: instead.")));
+ (void)setStatus:(NSString*)status; // change the HUD loading status while it's showing
// stops the activity indicator, shows a glyph + status, and dismisses the HUD a little bit later
+ (void)showInfoWithStatus:(NSString*)status;
+ (void)showInfoWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showInfoWithStatus: and setDefaultMaskType: instead.")));
+ (void)showSuccessWithStatus:(NSString*)status;
+ (void)showSuccessWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showSuccessWithStatus: and setDefaultMaskType: instead.")));
+ (void)showErrorWithStatus:(NSString*)status;
+ (void)showErrorWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showErrorWithStatus: and setDefaultMaskType: instead.")));
// shows a image + status, use 28x28 white PNGs
+ (void)showImage:(UIImage*)image status:(NSString*)status;
+ (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showImage:status: and setDefaultMaskType: instead.")));
+ (void)setOffsetFromCenter:(UIOffset)offset;
+ (void)resetOffsetFromCenter;
+ (void)popActivity; // decrease activity count, if activity count == 0 the HUD is dismissed
+ (void)dismiss;
+ (void)dismissWithDelay:(NSTimeInterval)delay;
+ (BOOL)isVisible;
+ (NSTimeInterval)displayDurationForString:(NSString*)string;
@end
//
// SVRadialGradientLayer.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2016 Tobias Tiemerding. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
@interface SVRadialGradientLayer : CALayer
@property (nonatomic) CGPoint gradientCenter;
@end
//
// SVRadialGradientLayer.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2016 Tobias Tiemerding. All rights reserved.
//
#import "SVRadialGradientLayer.h"
@implementation SVRadialGradientLayer
- (void)drawInContext:(CGContextRef)context {
size_t locationsCount = 2;
CGFloat locations[2] = {0.0f, 1.0f};
CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount);
CGColorSpaceRelease(colorSpace);
float radius = MIN(self.bounds.size.width , self.bounds.size.height);
CGContextDrawRadialGradient (context, gradient, self.gradientCenter, 0, self.gradientCenter, radius, kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradient);
}
@end
......@@ -25,20 +25,7 @@ class NewCKVc: BaseViewController,UITableViewDelegate,UITableViewDataSource,CKNo
func Print_Gprinter_View_Print(data: Array<Dictionary<String, Any>>) {
print("打印")
let dele = UIApplication.shared.delegate as! AppDelegate
// let tscCmd = TscCommand()
// tscCmd.hasResponse = true
// tscCmd.addSize(50, 30)
// tscCmd.addGap(withM: 2, withN: 0)
// tscCmd.addReference(24, 24)
// tscCmd.addSpeed(4)
// tscCmd.addDensity(8)
// tscCmd.addDirection(0)
// tscCmd.addComonCommand()
// tscCmd.addCls()
// tscCmd.addQRCode(20, 4, "G", 4, "L", 0, "格利IOS蓝牙打印")
// tscCmd.addPrint(1, 1)
......@@ -154,18 +141,7 @@ class NewCKVc: BaseViewController,UITableViewDelegate,UITableViewDataSource,CKNo
var goodsInfoArr:Array<Any> = []
@IBOutlet weak var gm_view: UIView!
@IBAction func ck_action(_ sender: UIButton) {
print("pw = ",BLKWrite.instance()?.printWidth())
let esc = EscCommand()
esc.hasResponse = true
esc.addInitializePrinter()
esc.addText("测试")
esc.addPrintMode(0x1B)
esc.addPrintAndFeedLines(8)
BLKWrite.instance()?.writeEscData(esc.getCommand(), withResponse: esc.hasResponse)
return
if isGm {
if typeSelect == nil {
HUD.flash(.label("请选择出库类型"),delay: 1.2)
......
//
// BtViewController.h
// GeliBusinessPlatform
//
// Created by junye lu on 2021/2/26.
// Copyright © 2021 junye lu. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface BtViewController : UIViewController
@end
NS_ASSUME_NONNULL_END
//
// BtViewController.m
// GeliBusinessPlatform
//
// Created by junye lu on 2021/2/26.
// Copyright © 2021 junye lu. All rights reserved.
//
#import "BtViewController.h"
#import "HLBLEManager.h"
#import "SVProgressHUD.h"
@interface BtViewController ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic)NSMutableArray *deviceArray; /**< 蓝牙设备个数 */
@property (strong, nonatomic)NSMutableArray *selectArray;//选择蓝牙
@end
@implementation BtViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
_deviceArray = [[NSMutableArray alloc] init];
_tableView.rowHeight = 44;
HLBLEManager *manager = [HLBLEManager sharedInstance];
__weak HLBLEManager *weakManager = manager;
manager.stateUpdateBlock = ^(CBCentralManager *central) {
NSString *info = nil;
switch (central.state) {
case CBCentralManagerStatePoweredOn:
info = @"蓝牙已打开,并且可用";
//三种种方式
// 方式1
[weakManager scanForPeripheralsWithServiceUUIDs:nil options:nil];
// // 方式2
// [central scanForPeripheralsWithServices:nil options:nil];
// // 方式3
// [weakManager scanForPeripheralsWithServiceUUIDs:nil options:nil didDiscoverPeripheral:^(CBCentralManager *central, CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI) {
//
// }];
break;
case CBCentralManagerStatePoweredOff:
info = @"蓝牙可用,未打开";
break;
case CBCentralManagerStateUnsupported:
info = @"SDK不支持";
break;
case CBCentralManagerStateUnauthorized:
info = @"程序未授权";
break;
case CBCentralManagerStateResetting:
info = @"CBCentralManagerStateResetting";
break;
case CBCentralManagerStateUnknown:
info = @"CBCentralManagerStateUnknown";
break;
}
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
[SVProgressHUD showInfoWithStatus:info ];
};
manager.discoverPeripheralBlcok = ^(CBCentralManager *central, CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI) {
if (peripheral.name.length <= 0) {
return ;
}
if (self.deviceArray.count == 0) {
NSDictionary *dict = @{@"peripheral":peripheral, @"RSSI":RSSI};
[self.deviceArray addObject:dict];
} else {
BOOL isExist = NO;
for (int i = 0; i < self.deviceArray.count; i++) {
NSDictionary *dict = [self.deviceArray objectAtIndex:i];
CBPeripheral *per = dict[@"peripheral"];
if ([per.identifier.UUIDString isEqualToString:peripheral.identifier.UUIDString]) {
isExist = YES;
NSDictionary *dict = @{@"peripheral":peripheral, @"RSSI":RSSI};
[_deviceArray replaceObjectAtIndex:i withObject:dict];
}
}
if (!isExist) {
NSDictionary *dict = @{@"peripheral":peripheral, @"RSSI":RSSI};
[self.deviceArray addObject:dict];
}
}
[self.tableView reloadData];
};
}
@end
//
// ConnectViewController.h
// BLETR
//
// Created by D500 user on 12/9/26.
// Copyright (c) 2012 ISSC Technologies Corporation. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "CBController.h"
#import "DeviceInfo.h"
@interface ConnectViewController : CBController<UITableViewDataSource, UITextViewDelegate, UITableViewDelegate>
{
IBOutlet UITableView *devicesTableView;
UIActivityIndicatorView *activityIndicatorView;
UILabel *statusLabel;
NSTimer *refreshDeviceListTimer;
int connectionStatus;
//Derek
DeviceInfo *deviceInfo;
MyPeripheral *controlPeripheral;
NSMutableArray *connectedDeviceInfo;//stored for DeviceInfo object
NSMutableArray *connectingList;//stored for MyPeripheral object
UIBarButtonItem *refreshButton;
UIBarButtonItem *scanButton;
UIBarButtonItem *cancelButton;
UIBarButtonItem *uuidSettingButton;
}
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicatorView;
@property (nonatomic, retain) IBOutlet UILabel *statusLabel;
@property (assign) int connectionStatus;
@property (retain, nonatomic) IBOutlet UILabel *versionLabel;
- (IBAction)refreshDeviceList:(id)sender;
- (IBAction)actionButtonCancelScan:(id)sender;
- (IBAction)manualUUIDSetting:(id)sender;
- (IBAction)actionButtonDisconnect:(id)sender;
- (IBAction)actionButtonCancelConnect:(id)sender;
@end
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