Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsic committed Jul 15, 2022
1 parent 1e7c2b8 commit f9a793a
Show file tree
Hide file tree
Showing 97 changed files with 3,194 additions and 3,570 deletions.
Binary file removed Picture/sorgle1.png
Binary file not shown.
Binary file removed Picture/sorgle2.png
Binary file not shown.
Binary file removed Picture/sorgle3.png
Binary file not shown.
Binary file removed Picture/sorgle4.png
Binary file not shown.
Binary file added Pictures/sgqrcode_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/sgqrcode_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/sgqrcode_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/sgqrcode_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/sgqrcode_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pictures/sgqrcode_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
158 changes: 84 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,126 +1,136 @@

# SGQRCode

* `QQ群:825339547`
| Version | UIKit | Use |
|:-----:|:-----:|:-----:|
| 3.5x | iOS 9.0+ | Block
| 4.x | iOS 11.0+ | Delegate

* `注意:3.5.1 版本重构:API 功能的拓展及扫码识别优化`
* QQ群:825339547

## 主要内容的介绍
* [3.5.1版本 API 使用说明](https://github.com/kingsic/SGQRCode/wiki/3.5.1版本API说明)

* `生成二维码`<br>

* `扫描二维码`<br>
## 主要功能

* `从相册中读取二维码`<br>
`生成二维码`<br>

* `根据光线强弱开启手电筒`<br>
`扫描二维码`<br>

* `扫描成功之后界面之间逻辑跳转处理`<br>
`手动对焦功能`<br>

* `扫描界面可自定义(线扫描条样式以及网格样式)`<br>
`图片中识别二维码`<br>

* `扫描界面仿微信(请根据项目需求,自行布局或调整)`<br>
`相机、相册权限判断`<br>

`根据光线强弱开启关闭手电筒`<br>

## SGQRCode 集成
`扫描成功后界面间的逻辑跳转处理`<br>

* 1、CocoaPods 导入 pod 'SGQRCode', '~> 3.5.1'
`扫描界面可高度自定义(满足所有主流app)`<br>

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

## 主要类说明
| 类名 | 说明 |
|-----|-----|
| SGScanCode | 扫描二维码 |
| SGScanViewConfigure | 扫描视图属性配置 |
| SGScanView | 扫描视图 |
| SGPermission | 相册、相机权限管理 |
| SGTorch | 手电筒管理 |
| SGQRCodeLog | 调试日志 |

## 代码介绍 (详细使用,请参考 Demo)

#### 1、在 info.plist 中添加以下字段(iOS 10 之后需添加的字段)
## SGQRCode 集成流程

* `NSCameraUsageDescription (相机权限访问)`<br>
**手动集成**
`添加 SGQRCode 文件夹到工程中`

* `NSPhotoLibraryUsageDescription (相册权限访问)`<br>
**通过 CocoaPods 集成**
`pod 'SGQRCode', '~> 4.0.0'`

#### 2、二维码扫描

**Info.plist 添加以下字段**
`NSCameraUsageDescription (相机权限访问)`<br>

`NSPhotoLibraryUsageDescription (相册权限访问)`<br>


**引用头文件**
`#import <SGQRCode/SGQRCode.h>`


**扫描二维码相关代码**
```Objective-C
   /// 创建二维码扫描类
   // 创建二维码扫描类
  scanCode = [SGScanCode scanCode];

   /// 二维码扫描回调方法
   [scanCode scanWithController:self resultBlock:^(SGScanCode *scanCode, NSString *result) {
    <#code#>
}];

/// 开启二维码扫描回调方法: 需手动开启
[scanCode startRunningWithBefore:^{
// 在此可添加 HUD
} completion:^{
// 在此可移除 HUD
}];
// 预览视图,必须设置
scanCode.preview = self.view;

   // 遵循 SGScanCodeDelegate
   scanCode.delegate = self;

// 遵循 SGScanCodeSampleBufferDelegate
scanCode.sampleBufferDelegate = self;

/// 外界光线强弱值回调方法
[scanCode scanWithBrightnessBlock:^(SGScanCode *scanCode, CGFloat brightness) {
<#code#>
}];
// 开启扫描
[scanCode startRunning];

   /// 从相册中读取二维码回调方法
   [scanCode readWithResultBlock:^(SGScanCode *scanCode, NSString *result) {
    <#code#>
}];
// 结束扫描
[scanCode stopRunning];
```

#### 3、二维码生成
**Delegate 方法**
```Objective-C
// SGScanCodeDelegate
- (void)scanCode:(SGScanCode *)scanCode result:(NSString *)result {
<#code#>
}

// SGScanCodeSampleBufferDelegate
- (void)scanCode:(SGScanCode *)scanCode brightness:(CGFloat)brightness {
<#code#>
}
```

**图片中识别二维码代码**
```Objective-C
/// 常规二维码
_imageView.image = [SGCreateCode createQRCodeWithData:@"https://github.com/kingsic" size:size];
[scanCode readQRCode:image completion:^(NSString *result) {
<#code#>
}];
```
**生成二维码相关代码**
```Objective-C
// 普通二维码生成方法
[SGGenerateQRCode generateQRCodeWithData:data size:size];
/// 带 logo 的二维码
_imageView.image = [SGCreateCode createQRCodeWithData:@"https://github.com/kingsic" size:size logoImage:logoImage ratio:ratio];
// 带 logo 的二维码生成方法
[SGGenerateQRCode generateQRCodeWithData:data size:size logoImage:logoImage ratio:ratio];
```


## 效果图

![](https://github.com/kingsic/SGQRCode/raw/master/Picture/sorgle1.png) ![](https://github.com/kingsic/SGQRCode/raw/master/Picture/sorgle2.png)

![](https://github.com/kingsic/SGQRCode/raw/master/Picture/sorgle3.png) ![](https://github.com/kingsic/SGQRCode/raw/master/Picture/sorgle4.png)
<img src="https://github.com/kingsic/SGQRCode/raw/master/Pictures/sgqrcode_1.png" width="40%" height="40%"><img src="https://github.com/kingsic/SGQRCode/raw/master/Pictures/sgqrcode_2.png" width="40%" height="40%">
<img src="https://github.com/kingsic/SGQRCode/raw/master/Pictures/sgqrcode_3.png" width="40%" height="40%"><img src="https://github.com/kingsic/SGQRCode/raw/master/Pictures/sgqrcode_4.png" width="40%" height="40%">
<img src="https://github.com/kingsic/SGQRCode/raw/master/Pictures/sgqrcode_5.png" width="40%" height="40%"><img src="https://github.com/kingsic/SGQRCode/raw/master/Pictures/sgqrcode_6.png" width="40%" height="40%">


## 问题及解决方案

* 若在使用 CocoaPods 安装第三方时,出现 [!] Unable to find a specification for SGQRCode 提示时,打开终端先输入 pod repo remove master;执行完毕后再输入 pod setup 即可 (可能会等待一段时间)

* 参考资料 [iOS 从相册中读取条形码/二维码遇到的问题](https://blog.csdn.net/gaomingyangc/article/details/54017879)
* CIDetector 类只能识别图片中的二维码,目前暂不支持识别图片中的条形码 [解决方案](https://juejin.cn/post/6844903910428114952l)

* 3.5.0 版本支持 9.0+,之前的版本支持 8.0+(iOS 扫描支持 7.0+;从相册中读取二维码支持 8.0+)


## 更新介绍

* 2016-09-30 :新增从相册中读取二维码功能

* 2016-10-27 :解决从相册中读取二维码,取消选择返回时,图层卡死问题(修改了创建扫描边框问题)

* 2017-01-29 :对扫描二维码部分代码的封装;扫描视图布局采用 CALayer

* 2017-03-21 :v2.0.0 使用继承的思想进行二维码扫描管理

* 2017-05-16 :v2.0.5 使用封装的思想进行二维码扫描管理

* 2017-06-26 :v2.1.0 加入 CocoaPods 管理

* 2017-08-17 :v2.1.5 新增根据光线强弱判断是否打开手电筒

* 2017-08-23 :v2.1.6 扫描界面使用 UIBezierPath 布局且可根据不同需求实现自定义(扫描线条以及网格样式)

* 2018-02-08 :v2.2.0 新增新浪微博示例、新增从相册中读取二维码失败回调函数以及分类名称的更换

* 2018-11-09 :v3.0.0 版本重构:Block 取代 Delegate,更多内容请在 [releases](https://github.com/kingsic/SGQRCode/releases) 中查看

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

* 2021-05-30 :v3.5.0 版本重构:API 功能的拓展及扫码识别优化,更多内容请在 [releases](https://github.com/kingsic/SGQRCode/releases/tag/3.5.0) 中查看
## 更新说明

* 2021-07-05 :v3.5.1 版本重构:修复 [#163](https://github.com/kingsic/SGQRCode/issues/163) 问题,更多内容请在 [releases](https://github.com/kingsic/SGQRCode/releases/tag/3.5.1) 中查看

* 2022-07-16 :v4.0.0 版本重构:Delegate 取代 Block,新增手动对焦功能,优化拓展扫描视图,更多内容请在 [releases](https://github.com/kingsic/SGQRCode/releases/tag/4.0.0) 中查看


## 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.5.1'
s.version = '4.0.0'
s.summary = 'The easy to use bar code and QR code scan library for iOS'
s.homepage = 'https://github.com/kingsic/SGQRCode'
s.license = 'Apache-2.0'
s.authors = {'kingsic' => '[email protected]'}
s.platform = :ios, '9.0'
s.platform = :ios, '11.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
22 changes: 22 additions & 0 deletions SGQRCode/Category/UIImage+SGQRCode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// UIImage+SGQRCode.h
// SGQRCodeExample
//
// Created by kingsic on 2022/7/9.
// Copyright © 2022 kingsic. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UIImage (SGQRCode)
/// 加载资源包下的图片
///
/// @param name 资源包名
/// @param imageName 图片名称
+ (UIImage *)SG_imageWithResource:(NSString *)name imageName:(NSString *)imageName;

@end

NS_ASSUME_NONNULL_END
27 changes: 27 additions & 0 deletions SGQRCode/Category/UIImage+SGQRCode.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// UIImage+SGQRCode.m
// SGQRCodeExample
//
// Created by kingsic on 2022/7/9.
// Copyright © 2022 kingsic. All rights reserved.
//

#import "UIImage+SGQRCode.h"

@implementation UIImage (SGQRCode)

+ (UIImage *)SG_imageWithResource:(NSString *)name imageName:(NSString *)imageName {
/// 静态库 url 的获取
NSURL *url = [[NSBundle mainBundle] URLForResource:name withExtension:@"bundle"];
if (!url) {
/// 动态库 url 的获取
url = [[NSBundle bundleForClass:[self class]] URLForResource:name withExtension:@"bundle"];
}
NSBundle *bundle = [NSBundle bundleWithURL:url];

UIImage *image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil];

return image;
}

@end
39 changes: 0 additions & 39 deletions SGQRCode/SGAuthorization.h

This file was deleted.

Loading

0 comments on commit f9a793a

Please sign in to comment.