|
7 | 7 | // |
8 | 8 |
|
9 | 9 | #import <UIKit/UIKit.h> |
10 | | -@class SGQRCodeObtainConfigure, SGQRCodeObtain; |
| 10 | +@class SGQRCodeManager; |
11 | 11 |
|
12 | | -typedef void(^SGQRCodeObtainScanResultBlock)(SGQRCodeObtain *obtain, NSString *result); |
13 | | -typedef void(^SGQRCodeObtainScanBrightnessBlock)(SGQRCodeObtain *obtain, CGFloat brightness); |
14 | | -typedef void(^SGQRCodeObtainAlbumDidCancelImagePickerControllerBlock)(SGQRCodeObtain *obtain); |
15 | | -typedef void(^SGQRCodeObtainAlbumResultBlock)(SGQRCodeObtain *obtain, NSString *result); |
| 12 | +typedef enum : NSUInteger { |
| 13 | + SGAuthorizationStatusSuccess, |
| 14 | + SGAuthorizationStatusFail, |
| 15 | + SGAuthorizationStatusUnknown, |
| 16 | +} SGAuthorizationStatus; |
| 17 | + |
| 18 | +typedef void(^SGQRCodeManagerScanResultBlock)(SGQRCodeManager *manager, NSString *result); |
| 19 | +typedef void(^SGQRCodeManagerScanBrightnessBlock)(SGQRCodeManager *manager, CGFloat brightness); |
| 20 | +typedef void(^SGQRCodeManagerReadResultBlock)(SGQRCodeManager *manager, NSString *result); |
| 21 | +typedef void(^SGQRCodeManagerAlbumDidCancelBlock)(SGQRCodeManager *manager); |
| 22 | +typedef void(^SGQRCodeManagerAuthorizationBlock)(SGQRCodeManager *manager, SGAuthorizationStatus authorizationStatus); |
| 23 | + |
| 24 | +@interface SGQRCodeManager : NSObject |
| 25 | +/** 扫描区域,默认为整个视图,取值范围:0~1(以屏幕右上角为坐标原点)*/ |
| 26 | +@property (nonatomic, assign) CGRect scanArea; |
| 27 | +/** 捕获外界光线亮度,默认为:NO */ |
| 28 | +@property (nonatomic, assign) BOOL brightness; |
| 29 | +/** 判断相册访问权限是否授权 */ |
| 30 | +@property (nonatomic, assign) BOOL albumAuthorization; |
| 31 | +/** 打印信息,默认为:NO */ |
| 32 | +@property (nonatomic, assign) BOOL openLog; |
16 | 33 |
|
17 | | -@interface SGQRCodeObtain : NSObject |
18 | 34 | /** 类方法创建 */ |
19 | | -+ (instancetype)QRCodeObtain; |
| 35 | ++ (instancetype)QRCodeManager; |
| 36 | + |
| 37 | +/** 相机权限访问回调方法 */ |
| 38 | +- (void)authorizationStatusBlock:(SGQRCodeManagerAuthorizationBlock)block; |
| 39 | +/** 后置摄像头是否可用 */ |
| 40 | +- (BOOL)isCameraDeviceRearAvailable; |
| 41 | + |
| 42 | +/** 扫描二维码回调方法 */ |
| 43 | +- (void)scanWithController:(UIViewController *)controller resultBlock:(SGQRCodeManagerScanResultBlock)blcok; |
| 44 | +/** 扫描二维码时,捕获外界光线强弱回调方法(brightness = YES 时,此回调方法才有效)*/ |
| 45 | +- (void)scanWithBrightnessBlock:(SGQRCodeManagerScanBrightnessBlock)blcok; |
| 46 | + |
| 47 | +/** 从相册中读取二维码回调方法 */ |
| 48 | +- (void)readWithResultBlock:(SGQRCodeManagerReadResultBlock)block; |
| 49 | +/** 相册选择控制器取消按钮的点击回调方法 */ |
| 50 | +- (void)albumDidCancelBlock:(SGQRCodeManagerAlbumDidCancelBlock)block; |
| 51 | + |
| 52 | +/** 开启扫描回调 */ |
| 53 | +- (void)startRunningWithBefore:(void (^)(void))before completion:(void (^)(void))completion; |
| 54 | +/** 停止扫描 */ |
| 55 | +- (void)stopRunning; |
20 | 56 |
|
21 | 57 | #pragma mark - - 生成二维码相关方法 |
22 | | -/** |
23 | | - * 生成二维码 |
24 | | - * |
25 | | - * @param data 二维码数据 |
26 | | - * @param size 二维码大小 |
27 | | - */ |
| 58 | +/** 生成二维码 */ |
28 | 59 | + (UIImage *)generateQRCodeWithData:(NSString *)data size:(CGFloat)size; |
29 | 60 | /** |
30 | 61 | * 生成二维码(自定义颜色) |
@@ -57,35 +88,12 @@ typedef void(^SGQRCodeObtainAlbumResultBlock)(SGQRCodeObtain *obtain, NSString * |
57 | 88 | */ |
58 | 89 | + (UIImage *)generateQRCodeWithData:(NSString *)data size:(CGFloat)size logoImage:(UIImage *)logoImage ratio:(CGFloat)ratio logoImageCornerRadius:(CGFloat)logoImageCornerRadius logoImageBorderWidth:(CGFloat)logoImageBorderWidth logoImageBorderColor:(UIColor *)logoImageBorderColor; |
59 | 90 |
|
60 | | -#pragma mark - - 扫描二维码相关方法 |
61 | | -/** 创建扫描二维码方法 */ |
62 | | -- (void)establishQRCodeObtainScanWithController:(UIViewController *)controller configure:(SGQRCodeObtainConfigure *)configure; |
63 | | -/** 扫描二维码回调方法 */ |
64 | | -- (void)setBlockWithQRCodeObtainScanResult:(SGQRCodeObtainScanResultBlock)block; |
65 | | -/** 扫描二维码光线强弱回调方法;调用之前配置属性 sampleBufferDelegate 必须为 YES */ |
66 | | -- (void)setBlockWithQRCodeObtainScanBrightness:(SGQRCodeObtainScanBrightnessBlock)block; |
67 | | -/** 开启扫描回调方法 */ |
68 | | -- (void)startRunningWithBefore:(void (^)(void))before completion:(void (^)(void))completion; |
69 | | -/** 停止扫描方法 */ |
70 | | -- (void)stopRunning; |
71 | | - |
72 | 91 | /** 播放音效文件 */ |
73 | 92 | - (void)playSoundName:(NSString *)name; |
74 | 93 |
|
75 | | -#pragma mark - - 相册中读取二维码相关方法 |
76 | | -/** 创建相册并获取相册授权方法 */ |
77 | | -- (void)establishAuthorizationQRCodeObtainAlbumWithController:(UIViewController *)controller; |
78 | | -/** 判断相册访问权限是否授权 */ |
79 | | -@property (nonatomic, assign) BOOL isPHAuthorization; |
80 | | -/** 图片选择控制器取消按钮的点击回调方法 */ |
81 | | -- (void)setBlockWithQRCodeObtainAlbumDidCancelImagePickerController:(SGQRCodeObtainAlbumDidCancelImagePickerControllerBlock)block; |
82 | | -/** 相册中读取图片二维码信息回调方法 */ |
83 | | -- (void)setBlockWithQRCodeObtainAlbumResult:(SGQRCodeObtainAlbumResultBlock)block; |
84 | | - |
85 | | -#pragma mark - - 手电筒相关方法 |
86 | 94 | /** 打开手电筒 */ |
87 | | -- (void)openFlashlight; |
| 95 | +- (void)turnOnFlashlight; |
88 | 96 | /** 关闭手电筒 */ |
89 | | -- (void)closeFlashlight; |
| 97 | +- (void)turnOffFlashlight; |
90 | 98 |
|
91 | 99 | @end |
0 commit comments