Inherits from NSObject
Conforms to AVCaptureMetadataOutputObjectsDelegate
Declared in SGSScanUtil.h

Tasks

Other Methods

通过摄像头扫描

从图片中读取二维码信息

生成二维码/条形码

Properties

capturSessionState

摄像头设置状态

@property (nonatomic, assign, readonly) SGSCaptureSessionState capturSessionState

Declared In

SGSScanUtil.h

scanDelegate

代理

@property (nullable, nonatomic, weak) id<SGSScannerDelegate> scanDelegate

Declared In

SGSScanUtil.h

sessionRunning

摄像头是否在运行

@property (nonatomic, assign, readonly, getter=isSessionRunning) BOOL sessionRunning

Declared In

SGSScanUtil.h

Class Methods

defaultMetadataObjectTypes

扫一扫功能默认支持的识别类型(二维码/条形码)

+ (NSArray<NSString*> *)defaultMetadataObjectTypes

Return Value

@[AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code, AVMetadataObjectTypeQRCode];

Declared In

SGSScanUtil.h

generateBarcode:size:color:backgroundColor:

生成条形码

+ (nullable UIImage *)generateBarcode:(NSString *)code size:(CGSize)size color:(nullable UIColor *)color backgroundColor:(nullable UIColor *)backgroundColor

Parameters

size

条形码大小

color

条形码颜色

backgroundColor

背景颜色

message

条形码

Return Value

条形码图片

Declared In

SGSScanUtil.h

generateCodeImageWithType:message:size:color:backgroundColor:

根据类型生成编码图片

+ (nullable UIImage *)generateCodeImageWithType:(NSString *)type message:(NSString *)message size:(CGSize)size color:(nullable UIColor *)color backgroundColor:(nullable UIColor *)backgroundColor

Parameters

type

编码类型,例如:"CIQRCodeGenerator" 表示生成二维码图片

message

编码信息

size

图片大小

color

编码颜色,如果为空默认为黑色

backgroundColor

背景颜色,如果为空默认为白色

Return Value

二维码图片 or nil

Declared In

SGSScanUtil.h

generateQRCode:size:color:backgroundColor:

生成二维码图片

+ (nullable UIImage *)generateQRCode:(NSString *)code size:(CGSize)size color:(nullable UIColor *)color backgroundColor:(nullable UIColor *)backgroundColor

Parameters

size

二维码大小

color

二维码颜色,如果为空默认为黑色

backgroundColor

背景颜色,如果为空默认为白色

message

二维码信息

Return Value

二维码图片 or nil

Declared In

SGSScanUtil.h

generateQRCode:size:color:backgroundColor:logoImage:

生成中间有logo的二维码图片

+ (nullable UIImage *)generateQRCode:(NSString *)code size:(CGSize)size color:(nullable UIColor *)color backgroundColor:(nullable UIColor *)backgroundColor logoImage:(UIImage *)logo

Parameters

size

二维码大小

color

二维码颜色,如果为空默认为黑色

backgroundColor

背景颜色,如果为空默认为白色

logo

中间logo

message

二维码信息

Return Value

带logo的二维码图片 or nil

Declared In

SGSScanUtil.h

readQRCodeFromImage:

从图片中读取二维码信息

+ (nullable NSString *)readQRCodeFromImage:(UIImage *)qrcodeImage

Parameters

qrcodeImage

二维码图片

Return Value

二维码信息 or nil

Declared In

SGSScanUtil.h

Instance Methods

initWithPreviewView:regionOfInterest:metadataObjectTypes:scanDelegate:

实例化扫描工具,可通过配置识别类型实现扫描二维码、条形码、人脸识别等功能

- (instancetype)initWithPreviewView:(UIView *)previewView regionOfInterest:(CGRect)regionOfInterest metadataObjectTypes:(nullable NSArray<NSString*> *)metadataObjectTypes scanDelegate:(nullable id<SGSScannerDelegate>)delegate

Parameters

previewView

将要预览的视图

regionOfInterest

扫描有效区域

metadataObjectTypes

扫描支持的识别类型

handler

扫描结果,只有相机正常调用并且正式扫描之后才可能回调

Return Value

扫描工具实例

Declared In

SGSScanUtil.h

resetCaptureSessionPreset:

重置相机画面分辨率,初始默认为:AVCaptureSessionPresetHigh

- (void)resetCaptureSessionPreset:(NSString *)preset

Parameters

preset

相机画面分辨率

Declared In

SGSScanUtil.h

resetMetadataObjectTypes:

修改扫描识别类型

- (void)resetMetadataObjectTypes:(NSArray<NSString*> *)metadataObjectTypes

Parameters

metadataObjectTypes

扫描识别类型

Declared In

SGSScanUtil.h

resizeRectOfInterestForRect:

重置扫描区域

- (void)resizeRectOfInterestForRect:(CGRect)scanRect

Parameters

scanRect

扫描有效区域

Declared In

SGSScanUtil.h

resumeScan

在相机服务被中断之后,可在适当的时机调用该方法恢复

- (void)resumeScan

Declared In

SGSScanUtil.h

setTorchModeToOn:

打开/关闭闪光灯

- (void)setTorchModeToOn:(BOOL)on

Parameters

on

YES 打开; NO 关闭

Declared In

SGSScanUtil.h

setVideoZoomFactor:

修改相机聚焦系数

- (void)setVideoZoomFactor:(CGFloat)factor

Parameters

factor

相机聚焦系数

Declared In

SGSScanUtil.h

startScan

开始扫描

- (void)startScan

Declared In

SGSScanUtil.h

stopScan

停止扫描

- (void)stopScan

Declared In

SGSScanUtil.h

switchTorchMode

切换闪光灯状态

- (void)switchTorchMode

Declared In

SGSScanUtil.h

turnOffTorch

关闭闪光灯

- (void)turnOffTorch

Declared In

SGSScanUtil.h

turnOnTorch

打开闪光灯

- (void)turnOnTorch

Declared In

SGSScanUtil.h

videoMaxZoomFactor

获取相机最大聚焦系数

- (CGFloat)videoMaxZoomFactor

Return Value

相机最大聚焦系数

Declared In

SGSScanUtil.h