-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
547 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
|
||
Pod::Spec.new do |s| | ||
s.name = 'SGQRCode' | ||
s.version = '3.5.0' | ||
s.summary = 'An easy way to use BarCode and QRCode scan library for iOS' | ||
s.version = '3.5.1' | ||
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]'} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// SGAuthorization.h | ||
// SGQRCodeExample | ||
// | ||
// Created by kingsic on 2021/7/5. | ||
// Copyright © 2021年 kingsic. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
@class SGAuthorization; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
typedef enum : NSUInteger { | ||
/// 授权成功(第一次授权允许及已授权) | ||
SGAuthorizationStatusSuccess, | ||
/// 授权失败(已拒绝) | ||
SGAuthorizationStatusFail, | ||
/// 未知(受限制) | ||
SGAuthorizationStatusUnknown, | ||
} SGAuthorizationStatus; | ||
|
||
typedef void(^SGAVAuthorizationBlock)(SGAuthorization *authorization, SGAuthorizationStatus status); | ||
typedef void(^SGPHAuthorizationBlock)(SGAuthorization *authorization, SGAuthorizationStatus status); | ||
|
||
@interface SGAuthorization : NSObject | ||
/** 类方法创建 */ | ||
+ (instancetype)authorization; | ||
/** 打印信息,默认为:NO */ | ||
@property (nonatomic, assign) BOOL openLog; | ||
|
||
/** 相机授权回调方法 */ | ||
- (void)AVAuthorizationBlock:(SGAVAuthorizationBlock)block; | ||
/** 相册授权回调方法 */ | ||
- (void)PHAuthorizationBlock:(SGPHAuthorizationBlock)block; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// | ||
// SGAuthorization.h | ||
// SGQRCodeExample | ||
// | ||
// Created by kingsic on 2021/7/5. | ||
// Copyright © 2021年 kingsic. All rights reserved. | ||
// | ||
|
||
#import "SGAuthorization.h" | ||
#import <AVFoundation/AVFoundation.h> | ||
#import <Photos/Photos.h> | ||
|
||
@implementation SGAuthorization | ||
|
||
/** 类方法创建 */ | ||
+ (instancetype)authorization { | ||
return [[self alloc] init]; | ||
} | ||
|
||
/** 相机授权回调方法 */ | ||
- (void)AVAuthorizationBlock:(SGAVAuthorizationBlock)block { | ||
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; | ||
switch (status) { | ||
// 授权状态未确定 | ||
case AVAuthorizationStatusNotDetermined: { | ||
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { | ||
if (granted) { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
if (block) { | ||
block(self, SGAuthorizationStatusSuccess); | ||
} | ||
}); | ||
if (self.openLog) { | ||
NSLog(@"用户第一次允许访问相机权限"); | ||
} | ||
} else { | ||
if (self.openLog) { | ||
NSLog(@"用户第一次拒绝访问相机权限"); | ||
} | ||
} | ||
}]; | ||
break; | ||
} | ||
// 已授权 | ||
case AVAuthorizationStatusAuthorized: { | ||
if (block) { | ||
block(self, SGAuthorizationStatusSuccess); | ||
} | ||
if (self.openLog) { | ||
NSLog(@"用户已允许访问相机权限"); | ||
} | ||
break; | ||
} | ||
// 已拒绝 | ||
case AVAuthorizationStatusDenied: { | ||
if (block) { | ||
block(self, SGAuthorizationStatusFail); | ||
} | ||
if (self.openLog) { | ||
NSLog(@"用户已拒绝访问相机权限"); | ||
} | ||
break; | ||
} | ||
// 受限制 | ||
case AVAuthorizationStatusRestricted: { | ||
if (block) { | ||
block(self, SGAuthorizationStatusUnknown); | ||
} | ||
if (self.openLog) { | ||
NSLog(@"系统原因, 无法访问"); | ||
} | ||
break; | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
return; | ||
} | ||
|
||
/** 相册授权回调方法 */ | ||
- (void)PHAuthorizationBlock:(SGPHAuthorizationBlock)block { | ||
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; | ||
if (status == PHAuthorizationStatusNotDetermined) { | ||
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { | ||
if (status == PHAuthorizationStatusAuthorized) { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
if (block) { | ||
block(self, SGAuthorizationStatusSuccess); | ||
} | ||
}); | ||
if (self.openLog == YES) { | ||
NSLog(@"用户第一次同意访问相册权限"); | ||
} | ||
} else { | ||
if (self.openLog == YES) { | ||
NSLog(@"用户第一次拒绝访问相册权限"); | ||
} | ||
} | ||
}]; | ||
} else if (status == PHAuthorizationStatusAuthorized) { | ||
if (block) { | ||
block(self, SGAuthorizationStatusSuccess); | ||
} | ||
if (self.openLog == YES) { | ||
NSLog(@"用户已允许访问相册权限"); | ||
} | ||
} else if (status == PHAuthorizationStatusDenied) { | ||
if (block) { | ||
block(self, SGAuthorizationStatusFail); | ||
} | ||
if (self.openLog) { | ||
NSLog(@"用户已拒绝访问相册权限"); | ||
} | ||
} else if (status == PHAuthorizationStatusRestricted) { | ||
if (block) { | ||
block(self, SGAuthorizationStatusUnknown); | ||
} | ||
if (self.openLog) { | ||
NSLog(@"系统原因, 无法访问"); | ||
} | ||
} | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// SGCreateCode.h | ||
// SGQRCodeExample | ||
// | ||
// Created by kingsic on 2021/7/5. | ||
// Copyright © 2021 Sorgle. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface SGCreateCode : NSObject | ||
/** 生成二维码 */ | ||
+ (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size; | ||
/** | ||
* 生成二维码(自定义颜色) | ||
* | ||
* @param data 二维码数据 | ||
* @param size 二维码大小 | ||
* @param color 二维码颜色 | ||
* @param backgroundColor 二维码背景颜色 | ||
*/ | ||
+ (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size color:(UIColor *)color backgroundColor:(UIColor *)backgroundColor; | ||
/** | ||
* 生成带 logo 的二维码(推荐使用) | ||
* | ||
* @param data 二维码数据 | ||
* @param size 二维码大小 | ||
* @param logoImage logo | ||
* @param ratio logo 相对二维码的比例(取值范围 0.0 ~ 0.5f) | ||
*/ | ||
+ (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size logoImage:(UIImage *)logoImage ratio:(CGFloat)ratio; | ||
/** | ||
* 生成带 logo 的二维码(拓展) | ||
* | ||
* @param data 二维码数据 | ||
* @param size 二维码大小 | ||
* @param logoImage logo | ||
* @param ratio logo 相对二维码的比例(取值范围 0.0 ~ 0.5f) | ||
* @param logoImageCornerRadius logo 外边框圆角(取值范围 0.0 ~ 10.0f) | ||
* @param logoImageBorderWidth logo 外边框宽度(取值范围 0.0 ~ 10.0f) | ||
* @param logoImageBorderColor logo 外边框颜色 | ||
*/ | ||
+ (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size logoImage:(UIImage *)logoImage ratio:(CGFloat)ratio logoImageCornerRadius:(CGFloat)logoImageCornerRadius logoImageBorderWidth:(CGFloat)logoImageBorderWidth logoImageBorderColor:(UIColor *)logoImageBorderColor; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// SGCreateCode.m | ||
// SGQRCodeExample | ||
// | ||
// Created by kingsic on 2021/7/5. | ||
// Copyright © 2021 Sorgle. All rights reserved. | ||
// | ||
|
||
#import "SGCreateCode.h" | ||
|
||
@implementation SGCreateCode | ||
|
||
+ (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size { | ||
return [self createQRCodeWithData:data size:size color:[UIColor blackColor] backgroundColor:[UIColor whiteColor]]; | ||
} | ||
|
||
+ (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size color:(UIColor *)color backgroundColor:(UIColor *)backgroundColor { | ||
NSData *string_data = [data dataUsingEncoding:NSUTF8StringEncoding]; | ||
// 1、二维码滤镜 | ||
CIFilter *fileter = [CIFilter filterWithName:@"CIQRCodeGenerator"]; | ||
[fileter setValue:string_data forKey:@"inputMessage"]; | ||
[fileter setValue:@"H" forKey:@"inputCorrectionLevel"]; | ||
CIImage *ciImage = fileter.outputImage; | ||
// 2、颜色滤镜 | ||
CIFilter *color_filter = [CIFilter filterWithName:@"CIFalseColor"]; | ||
[color_filter setValue:ciImage forKey:@"inputImage"]; | ||
[color_filter setValue:[CIColor colorWithCGColor:color.CGColor] forKey:@"inputColor0"]; | ||
[color_filter setValue:[CIColor colorWithCGColor:backgroundColor.CGColor] forKey:@"inputColor1"]; | ||
// 3、生成处理 | ||
CIImage *outImage = color_filter.outputImage; | ||
CGFloat scale = size / outImage.extent.size.width; | ||
outImage = [outImage imageByApplyingTransform:CGAffineTransformMakeScale(scale, scale)]; | ||
return [UIImage imageWithCIImage:outImage]; | ||
} | ||
|
||
+ (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size logoImage:(UIImage *)logoImage ratio:(CGFloat)ratio { | ||
return [self createQRCodeWithData:data size:size logoImage:logoImage ratio:ratio logoImageCornerRadius:5 logoImageBorderWidth:5 logoImageBorderColor:[UIColor whiteColor]]; | ||
} | ||
|
||
+ (UIImage *)createQRCodeWithData:(NSString *)data size:(CGFloat)size logoImage:(UIImage *)logoImage ratio:(CGFloat)ratio logoImageCornerRadius:(CGFloat)logoImageCornerRadius logoImageBorderWidth:(CGFloat)logoImageBorderWidth logoImageBorderColor:(UIColor *)logoImageBorderColor { | ||
UIImage *image = [self createQRCodeWithData:data size:size color:[UIColor blackColor] backgroundColor:[UIColor whiteColor]]; | ||
if (logoImage == nil) return image; | ||
if (ratio < 0.0 || ratio > 0.5) { | ||
ratio = 0.25; | ||
} | ||
CGFloat logoImageW = ratio * size; | ||
CGFloat logoImageH = logoImageW; | ||
CGFloat logoImageX = 0.5 * (image.size.width - logoImageW); | ||
CGFloat logoImageY = 0.5 * (image.size.height - logoImageH); | ||
CGRect logoImageRect = CGRectMake(logoImageX, logoImageY, logoImageW, logoImageH); | ||
// 绘制logo | ||
UIGraphicsBeginImageContextWithOptions(image.size, false, [UIScreen mainScreen].scale); | ||
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; | ||
if (logoImageCornerRadius < 0.0 || logoImageCornerRadius > 10) { | ||
logoImageCornerRadius = 5; | ||
} | ||
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:logoImageRect cornerRadius:logoImageCornerRadius]; | ||
if (logoImageBorderWidth < 0.0 || logoImageBorderWidth > 10) { | ||
logoImageBorderWidth = 5; | ||
} | ||
path.lineWidth = logoImageBorderWidth; | ||
[logoImageBorderColor setStroke]; | ||
[path stroke]; | ||
[path addClip]; | ||
[logoImage drawInRect:logoImageRect]; | ||
UIImage *QRCodeImage = UIGraphicsGetImageFromCurrentImageContext(); | ||
UIGraphicsEndImageContext(); | ||
return QRCodeImage; | ||
} | ||
|
||
@end |
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
// | ||
// SGQRCode.h | ||
// Version 3.5.0 | ||
// Version 3.5.1 | ||
// https://github.com/kingsic/SGQRCode | ||
// | ||
// Created by kingsic on 2016/8/16. | ||
// Copyright © 2016年 kingsic. All rights reserved. | ||
// | ||
|
||
#import "SGQRCodeManager.h" | ||
#import "SGQRCodeScanView.h" | ||
#import "SGScanCode.h" | ||
#import "SGScanView.h" | ||
#import "SGCreateCode.h" | ||
#import "SGAuthorization.h" |
Oops, something went wrong.