Skip to content

Commit

Permalink
【版本进行了重构:扫码优化及api的拓展】
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsic committed May 30, 2021
1 parent ce956b9 commit d94437a
Show file tree
Hide file tree
Showing 13 changed files with 681 additions and 675 deletions.
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

* `QQ群:825339547`

* `温馨提示:v3.0.0 Block 取代 Delegate`

* `注意:3.5.0 版本进行了重构`

## 主要内容的介绍

Expand All @@ -26,7 +25,7 @@

## SGQRCode 集成

* 1、CocoaPods 导入 pod 'SGQRCode', '~> 3.0.1'
* 1、CocoaPods 导入 pod 'SGQRCode', '~> 3.5.0'

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

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

```Objective-C
__weak typeof(self) weakSelf = self;

   /// 创建二维码扫描
SGQRCodeObtainConfigure *configure = [SGQRCodeObtainConfigure QRCodeObtainConfigure];
[obtain establishQRCodeObtainScanWithController:self configure:configure];
// 二维码扫描回调方法
[obtain setBlockWithQRCodeObtainScanResult:^(SGQRCodeObtain *obtain, NSString *result) {
<#code#>
   /// 创建二维码扫描类
   SGQRCodeManager manager = [SGQRCodeManager QRCodeManager];
   /// 二维码扫描回调方法
   [manager scanWithController:self resultBlock:^(SGQRCodeManager *manager, NSString *result) {
    <#code#>
}];
// 二维码扫描开启方法: 需手动开启
[obtain startRunningWithBefore:^{

/// 开启二维码扫描回调方法: 需手动开启
[manager startRunningWithBefore:^{
// 在此可添加 HUD
} completion:^{
// 在此可移除 HUD
}];
// 根据外界光线强弱值判断是否自动开启手电筒
[obtain setBlockWithQRCodeObtainScanBrightness:^(SGQRCodeObtain *obtain, CGFloat brightness) {

/// 外界光线强弱值回调方法
[manager scanWithBrightnessBlock:^(SGQRCodeManager *manager, CGFloat brightness) {
<#code#>
}];

   /// 从相册中读取二维码
[obtain establishAuthorizationQRCodeObtainAlbumWithController:self];
// 从相册中读取图片上的二维码回调方法
[obtain setBlockWithQRCodeObtainAlbumResult:^(SGQRCodeObtain *obtain, NSString *result) {
<#code#>
   /// 从相册中读取二维码回调方法
   [manager readWithResultBlock:^(SGQRCodeManager *manager, NSString *result) {
    <#code#>
}];
```
Expand Down Expand Up @@ -94,7 +90,7 @@

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

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

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

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

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


## License
SGQRCode is released under the Apache License 2.0. See [LICENSE](https://github.com/kingsic/SGQRCode/blob/master/LICENSE) for details.
4 changes: 2 additions & 2 deletions SGQRCode.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

Pod::Spec.new do |s|
s.name = 'SGQRCode'
s.version = '3.0.1'
s.version = '3.5.0'
s.summary = 'An easy way to use BarCode and QRCode scan library for iOS'
s.homepage = 'https://github.com/kingsic/SGQRCode'
s.license = 'Apache-2.0'
s.authors = {'kingsic' => '[email protected]'}
s.platform = :ios, '8.0'
s.platform = :ios, '9.0'
s.source = {:git => 'https://github.com/kingsic/SGQRCode.git', :tag => s.version}
s.source_files = 'SGQRCode/**/*.{h,m}'
s.resource = 'SGQRCode/SGQRCode.bundle'
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions SGQRCode/SGQRCode.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//
// SGQRCode.h
// Version 3.0.1
// Version 3.5.0
// https://github.com/kingsic/SGQRCode
//
// Created by kingsic on 2016/8/16.
// Copyright © 2016年 kingsic. All rights reserved.
//

#import "SGQRCodeObtainConfigure.h"
#import "SGQRCodeObtain.h"
#import "SGQRCodeManager.h"
#import "SGQRCodeScanView.h"
84 changes: 46 additions & 38 deletions SGQRCode/SGQRCodeObtain.h → SGQRCode/SGQRCodeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,55 @@
//

#import <UIKit/UIKit.h>
@class SGQRCodeObtainConfigure, SGQRCodeObtain;
@class SGQRCodeManager;

typedef void(^SGQRCodeObtainScanResultBlock)(SGQRCodeObtain *obtain, NSString *result);
typedef void(^SGQRCodeObtainScanBrightnessBlock)(SGQRCodeObtain *obtain, CGFloat brightness);
typedef void(^SGQRCodeObtainAlbumDidCancelImagePickerControllerBlock)(SGQRCodeObtain *obtain);
typedef void(^SGQRCodeObtainAlbumResultBlock)(SGQRCodeObtain *obtain, NSString *result);
typedef enum : NSUInteger {
SGAuthorizationStatusSuccess,
SGAuthorizationStatusFail,
SGAuthorizationStatusUnknown,
} SGAuthorizationStatus;

typedef void(^SGQRCodeManagerScanResultBlock)(SGQRCodeManager *manager, NSString *result);
typedef void(^SGQRCodeManagerScanBrightnessBlock)(SGQRCodeManager *manager, CGFloat brightness);
typedef void(^SGQRCodeManagerReadResultBlock)(SGQRCodeManager *manager, NSString *result);
typedef void(^SGQRCodeManagerAlbumDidCancelBlock)(SGQRCodeManager *manager);
typedef void(^SGQRCodeManagerAuthorizationBlock)(SGQRCodeManager *manager, SGAuthorizationStatus authorizationStatus);

@interface SGQRCodeManager : NSObject
/** 扫描区域,默认为整个视图,取值范围:0~1(以屏幕右上角为坐标原点)*/
@property (nonatomic, assign) CGRect scanArea;
/** 捕获外界光线亮度,默认为:NO */
@property (nonatomic, assign) BOOL brightness;
/** 判断相册访问权限是否授权 */
@property (nonatomic, assign) BOOL albumAuthorization;
/** 打印信息,默认为:NO */
@property (nonatomic, assign) BOOL openLog;

@interface SGQRCodeObtain : NSObject
/** 类方法创建 */
+ (instancetype)QRCodeObtain;
+ (instancetype)QRCodeManager;

/** 相机权限访问回调方法 */
- (void)authorizationStatusBlock:(SGQRCodeManagerAuthorizationBlock)block;
/** 后置摄像头是否可用 */
- (BOOL)isCameraDeviceRearAvailable;

/** 扫描二维码回调方法 */
- (void)scanWithController:(UIViewController *)controller resultBlock:(SGQRCodeManagerScanResultBlock)blcok;
/** 扫描二维码时,捕获外界光线强弱回调方法(brightness = YES 时,此回调方法才有效)*/
- (void)scanWithBrightnessBlock:(SGQRCodeManagerScanBrightnessBlock)blcok;

/** 从相册中读取二维码回调方法 */
- (void)readWithResultBlock:(SGQRCodeManagerReadResultBlock)block;
/** 相册选择控制器取消按钮的点击回调方法 */
- (void)albumDidCancelBlock:(SGQRCodeManagerAlbumDidCancelBlock)block;

/** 开启扫描回调 */
- (void)startRunningWithBefore:(void (^)(void))before completion:(void (^)(void))completion;
/** 停止扫描 */
- (void)stopRunning;

#pragma mark - - 生成二维码相关方法
/**
* 生成二维码
*
* @param data 二维码数据
* @param size 二维码大小
*/
/** 生成二维码 */
+ (UIImage *)generateQRCodeWithData:(NSString *)data size:(CGFloat)size;
/**
* 生成二维码(自定义颜色)
Expand Down Expand Up @@ -57,35 +88,12 @@ typedef void(^SGQRCodeObtainAlbumResultBlock)(SGQRCodeObtain *obtain, NSString *
*/
+ (UIImage *)generateQRCodeWithData:(NSString *)data size:(CGFloat)size logoImage:(UIImage *)logoImage ratio:(CGFloat)ratio logoImageCornerRadius:(CGFloat)logoImageCornerRadius logoImageBorderWidth:(CGFloat)logoImageBorderWidth logoImageBorderColor:(UIColor *)logoImageBorderColor;

#pragma mark - - 扫描二维码相关方法
/** 创建扫描二维码方法 */
- (void)establishQRCodeObtainScanWithController:(UIViewController *)controller configure:(SGQRCodeObtainConfigure *)configure;
/** 扫描二维码回调方法 */
- (void)setBlockWithQRCodeObtainScanResult:(SGQRCodeObtainScanResultBlock)block;
/** 扫描二维码光线强弱回调方法;调用之前配置属性 sampleBufferDelegate 必须为 YES */
- (void)setBlockWithQRCodeObtainScanBrightness:(SGQRCodeObtainScanBrightnessBlock)block;
/** 开启扫描回调方法 */
- (void)startRunningWithBefore:(void (^)(void))before completion:(void (^)(void))completion;
/** 停止扫描方法 */
- (void)stopRunning;

/** 播放音效文件 */
- (void)playSoundName:(NSString *)name;

#pragma mark - - 相册中读取二维码相关方法
/** 创建相册并获取相册授权方法 */
- (void)establishAuthorizationQRCodeObtainAlbumWithController:(UIViewController *)controller;
/** 判断相册访问权限是否授权 */
@property (nonatomic, assign) BOOL isPHAuthorization;
/** 图片选择控制器取消按钮的点击回调方法 */
- (void)setBlockWithQRCodeObtainAlbumDidCancelImagePickerController:(SGQRCodeObtainAlbumDidCancelImagePickerControllerBlock)block;
/** 相册中读取图片二维码信息回调方法 */
- (void)setBlockWithQRCodeObtainAlbumResult:(SGQRCodeObtainAlbumResultBlock)block;

#pragma mark - - 手电筒相关方法
/** 打开手电筒 */
- (void)openFlashlight;
- (void)turnOnFlashlight;
/** 关闭手电筒 */
- (void)closeFlashlight;
- (void)turnOffFlashlight;

@end
Loading

0 comments on commit d94437a

Please sign in to comment.