Skip to content

Commit d94437a

Browse files
committed
【版本进行了重构:扫码优化及api的拓展】
1 parent ce956b9 commit d94437a

File tree

13 files changed

+681
-675
lines changed

13 files changed

+681
-675
lines changed

README.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
* `QQ群:825339547`
66

7-
* `温馨提示:v3.0.0 Block 取代 Delegate`
8-
7+
* `注意:3.5.0 版本进行了重构`
98

109
## 主要内容的介绍
1110

@@ -26,7 +25,7 @@
2625

2726
## SGQRCode 集成
2827

29-
* 1、CocoaPods 导入 pod 'SGQRCode', '~> 3.0.1'
28+
* 1、CocoaPods 导入 pod 'SGQRCode', '~> 3.5.0'
3029

3130
* 2、下载、拖拽 “SGQRCode” 文件夹到工程中
3231

@@ -42,31 +41,28 @@
4241
#### 2、二维码扫描
4342

4443
```Objective-C
45-
__weak typeof(self) weakSelf = self;
46-
47-
   /// 创建二维码扫描
48-
SGQRCodeObtainConfigure *configure = [SGQRCodeObtainConfigure QRCodeObtainConfigure];
49-
[obtain establishQRCodeObtainScanWithController:self configure:configure];
50-
// 二维码扫描回调方法
51-
[obtain setBlockWithQRCodeObtainScanResult:^(SGQRCodeObtain *obtain, NSString *result) {
52-
<#code#>
44+
   /// 创建二维码扫描类
45+
   SGQRCodeManager manager = [SGQRCodeManager QRCodeManager];
46+
   /// 二维码扫描回调方法
47+
   [manager scanWithController:self resultBlock:^(SGQRCodeManager *manager, NSString *result) {
48+
    <#code#>
5349
}];
54-
// 二维码扫描开启方法: 需手动开启
55-
[obtain startRunningWithBefore:^{
50+
51+
/// 开启二维码扫描回调方法: 需手动开启
52+
[manager startRunningWithBefore:^{
5653
// 在此可添加 HUD
5754
} completion:^{
5855
// 在此可移除 HUD
5956
}];
60-
// 根据外界光线强弱值判断是否自动开启手电筒
61-
[obtain setBlockWithQRCodeObtainScanBrightness:^(SGQRCodeObtain *obtain, CGFloat brightness) {
57+
58+
/// 外界光线强弱值回调方法
59+
[manager scanWithBrightnessBlock:^(SGQRCodeManager *manager, CGFloat brightness) {
6260
<#code#>
6361
}];
6462

65-
   /// 从相册中读取二维码
66-
[obtain establishAuthorizationQRCodeObtainAlbumWithController:self];
67-
// 从相册中读取图片上的二维码回调方法
68-
[obtain setBlockWithQRCodeObtainAlbumResult:^(SGQRCodeObtain *obtain, NSString *result) {
69-
<#code#>
63+
   /// 从相册中读取二维码回调方法
64+
   [manager readWithResultBlock:^(SGQRCodeManager *manager, NSString *result) {
65+
    <#code#>
7066
}];
7167
```
7268
@@ -94,7 +90,7 @@
9490

9591
* 参考资料 [iOS 从相册中读取条形码/二维码遇到的问题](https://blog.csdn.net/gaomingyangc/article/details/54017879)
9692

97-
* iOS 扫描支持 7.0+;从相册中读取二维码支持 8.0+;因此,CocoaPods 版本最低支持 8.0+
93+
* iOS 扫描支持 7.0+;从相册中读取二维码支持 8.0+;因此,CocoaPods 版本最低支持 8.0+,本库由于内部方法的使用,最低支持系统 9.0
9894

9995
* 关于条形码扫不出来的问题
10096
* 参考案例 WBQRCodeVC 中的代码,设置支持条形码扫描识别类型的属性 ‘metadataObjectTypes’ 即可
@@ -125,6 +121,8 @@
125121

126122
* 2018-11-27 :v3.0.1 SGQRCodeObtain 类中新增二维码生成方法
127123

124+
* 2021-05-30 :v3.5.0 删除了配置类及管理类名的更换,API 的拓展及扫码优化
125+
128126

129127
## License
130128
SGQRCode is released under the Apache License 2.0. See [LICENSE](https://github.com/kingsic/SGQRCode/blob/master/LICENSE) for details.

SGQRCode.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
Pod::Spec.new do |s|
33
s.name = 'SGQRCode'
4-
s.version = '3.0.1'
4+
s.version = '3.5.0'
55
s.summary = 'An easy way to use BarCode and QRCode scan library for iOS'
66
s.homepage = 'https://github.com/kingsic/SGQRCode'
77
s.license = 'Apache-2.0'
88
s.authors = {'kingsic' => 'kingsic@126.com'}
9-
s.platform = :ios, '8.0'
9+
s.platform = :ios, '9.0'
1010
s.source = {:git => 'https://github.com/kingsic/SGQRCode.git', :tag => s.version}
1111
s.source_files = 'SGQRCode/**/*.{h,m}'
1212
s.resource = 'SGQRCode/SGQRCode.bundle'
File renamed without changes.

SGQRCode/SGQRCode.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//
22
// SGQRCode.h
3-
// Version 3.0.1
3+
// Version 3.5.0
44
// https://github.com/kingsic/SGQRCode
55
//
66
// Created by kingsic on 2016/8/16.
77
// Copyright © 2016年 kingsic. All rights reserved.
88
//
99

10-
#import "SGQRCodeObtainConfigure.h"
11-
#import "SGQRCodeObtain.h"
10+
#import "SGQRCodeManager.h"
1211
#import "SGQRCodeScanView.h"
Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,55 @@
77
//
88

99
#import <UIKit/UIKit.h>
10-
@class SGQRCodeObtainConfigure, SGQRCodeObtain;
10+
@class SGQRCodeManager;
1111

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;
1633

17-
@interface SGQRCodeObtain : NSObject
1834
/** 类方法创建 */
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;
2056

2157
#pragma mark - - 生成二维码相关方法
22-
/**
23-
* 生成二维码
24-
*
25-
* @param data 二维码数据
26-
* @param size 二维码大小
27-
*/
58+
/** 生成二维码 */
2859
+ (UIImage *)generateQRCodeWithData:(NSString *)data size:(CGFloat)size;
2960
/**
3061
* 生成二维码(自定义颜色)
@@ -57,35 +88,12 @@ typedef void(^SGQRCodeObtainAlbumResultBlock)(SGQRCodeObtain *obtain, NSString *
5788
*/
5889
+ (UIImage *)generateQRCodeWithData:(NSString *)data size:(CGFloat)size logoImage:(UIImage *)logoImage ratio:(CGFloat)ratio logoImageCornerRadius:(CGFloat)logoImageCornerRadius logoImageBorderWidth:(CGFloat)logoImageBorderWidth logoImageBorderColor:(UIColor *)logoImageBorderColor;
5990

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-
7291
/** 播放音效文件 */
7392
- (void)playSoundName:(NSString *)name;
7493

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 - - 手电筒相关方法
8694
/** 打开手电筒 */
87-
- (void)openFlashlight;
95+
- (void)turnOnFlashlight;
8896
/** 关闭手电筒 */
89-
- (void)closeFlashlight;
97+
- (void)turnOffFlashlight;
9098

9199
@end

0 commit comments

Comments
 (0)