统一标识代码注册管理中心

首页 开放平台 下载SDK 开发者指南 登录注册

技术文档 >> IOS版SDK 开发指南

Android版SDK 开发指南

简介

申请授权

接入指南

SDK 下载

IOS版SDK 开发指南

简介

接入指南

SDK 下载

接入指南

2.1 下载SDK

下载 IOS 版sdk.zip并解压缩

2.2 导入SDK

将下载包中的lib 文件夹合并到本地工程lib子目录下;在xcode中右键工程根目录,选择Add Files to ,然后选择lib路径,点击Add,即导入成功。

2.3 配置framework

将项目需要的framework添加至您的app中,详细列表如下:

libstdc++.6.0.9.tbd

libz.1.2.5.tbd

libiconv.2.4.0.tbd

AudioToolbox.framework

AVFoundation.framework

CoreVideo.framework

CoreMedia.framework

CoreGraphics.framework

CFNetwork.framework

Foundation.framework

MobileCoreServices.framework

QuartzCore.framework

SystemConfiguration.framework

UIKit.framework

AddressBookUI.framework

AddressBook.framework

CoreImage.framework

libstdc++.tbd

2.4 修改App Setting

1. 选择Build Settings,在Other Linker Flags 中添加-ObjC

2. 选择Build Settings,修改 Enable Bitcode 的值为NO

3. 修改C Language Dialect的值为Compiler Default,修改C++ Language Dialect 的值为Compiler Default,修改C++ Standard Library的值为Compiler Default。

4. 开发者若要返回的提示信息为中文,请添加中文支持,如下图:

5. 编辑Info.plist 添加设置App Transport Security Settings,如图

6. 编辑Info.plist 添加设置Privacy - Camera Usage Description 和 Privacy - Photo Library Usage Description 如图:

2.5 获得Appkey

在IDcode的管理后台中创建App并获得AppKey

1、 登录后创建应用

2、 填写应用信息

IOS应用Bundle ID:应用中Bundle Identifier

3、 点击下一步,完成应用申请获取key

4、 申请成功后的应用,可在应用列表中查看

2.6 SDK调用示例

2.6.1 解码调用

1. 创建解码成员变量

//创建解码成员变量
DecodeImage *_scanSDK;

2. 实例化解码对象

//实例化解码对象
/**********************************************************
函数名称:- (id)initWithDelegate:(id)delegate key:(NSString *)keystr;
函数描述:实例化对象,并设置代理
输入参数:(id)delegate:代理对象
输入参数:key:(NSString *)keystr 开放平台申请的key
输出参数:Null
返回值:id:实例化后的DecodeImage对象
*********************************************************/
DecodeImage *decode=[[DecodeImage alloc] initWithDelegate:self key:APP_KEY];
//设置是否进行安全筛选,默认为yes(进行安全筛选)
decode.isScanFilter = YES;
//设置码制集合,如不设默认全部码制。
NSArray *readerArr = [NSMutableArray arrayWithObject:[NSNumber numberWithInt:ReaderSetTypeQR]];
[decode setReaderArray:readerArr];
_scanSDK=decode;

APP_KEY:是在开放平台分配的应用授权key.

3. 调用解码功能

UIImage *img = [UIImage imageNamed:@"ceshi.png"];
if (img) {
/**********************************************************
函数名称:- (void)decodeImage:(UIImage *)image;
函数描述:解读图片中包含的二维码(或一维码)
输入参数:(UIImage *)image:被解读的图片
输出参数:Null
返回值:void
**********************************************************/
[_scanSDK decodeImage:img];
}

4. 实现解码代理

//解码成功
- (void)scanFinish:(DecodeImage *)decodeObj scanResult:(sdk_ScanResult *)scanResult{
if (scanResult.resultFlag) {
//内容安全
//码内容
_lbl.text = scanResult.content;
//码图片
_imgView.image = scanResult.image;
//码类型
_type.text=scanResult.codeTypeStr;
}else{
//内容不安全
Toast *toast = [[Toast alloc] initWithText:@"码内容是非法网址" superView:self.view];
[toast show];
}
}

//解码失败
-(void)scanFail:(DecodeImage *)decodeObj failMessage:(NSString *)messge failType:(int)failType{
//messge为解码失败原因
Toast *toast = [[Toast alloc] initWithText:messge superView:self.view];
[toast show];
// failType:失败原因 (1:解码失败 2:其它)
}
/**********************************************************
函数名称:-(void)filterStart:(DecodeImage *)decodeObj;
函数描述:如果需要安全过滤,扫描出结果开始安全过滤师调用
输入参数:(DecodeImage *)decodeObj:依托的DecodeImage的对象
输出参数:Null
返回值:void
**********************************************************/
-(void)filterStart:(DecodeImage *)decodeObj;

2.6.2生成码调用

建议:生成的码图大小要大于100个像素,生成码后要在正式应用环境实际拍摄成功后应用,以防因码信息密度过大或拍摄器械原因不能识别或识别错误造成损失。

1. 创建生成码成员变量

//生成码对象
CreateCodeImage *_encodeSDK;

2. 实例化生成码对象

//实例化生成码对象
/**********************************************************
函数名称:- (id)initWithKey:(NSString *)keystr;
函数描述:实例化对象
输入参数:(NSString *)keystr 开放平台申请的key
输出参数:Null
返回值:id:实例化后的CreateCodeImage对象
**********************************************************/
CreateCodeImage *encode=[[CreateCodeImage alloc] initWithKey:APP_KEY];
//设生成码过程中的输出界面,如不设popViewControler静态库不进行任何提示
encode.popViewControler=self;
//设置是否进行安全筛选,默认为yes(进行安全筛选)
encode.isFilter = YES;
_encodeSDK=encode;
(如未设popViewControler,则静态库不进行任何错误提示,用户可根据CreateCodeImage 中的errorMessage自行提示)

APP_KEY:是在开放平台分配的应用授权key

3. 调用生成码功能

接口1:默认QR码设置为:前景色:黑色,背景色:白色。

/*********************************************************
函数名称:-(void)encode:(NSString *)code width:(int)codeWidth height:(int)codeHeight type:(int)codeType
block:(void(^)(UIImage *,NSString *))block;
函数描述:生成码
输入参数:(NSString *)code 要生成的码内容
输入参数:width:(int)codeWidth 码宽
输入参数:heigh:(int)codeHeight 码高
输入参数:type:(int)codeType 码格式(0:QR码,1:GM,3:汉信,4:龙贝码,5:DM码)
输入参数:block:(void(^)(UIImage *,NSString *))block 回调代码块,UIImage *:生成码图,NSString *:错误信息
返回值:void
**********************************************************/
__weak typeof (self) weakSelf = self;
[_encodeSDK encode:code width:200 height:200 type:0 block:^(UIImage * img, NSString *error) {
if (error) {
//生成码错误信息
Toast *toast = [[Toast alloc] initWithText: error superView: weakSelf.view];
[toast show];
}else{
_imgView.image = img;
}
}];

接口2:可设置QR码:前景色,背景色,纠错级别。

/**********************************************************
函数名称:-(void)encode:(NSString *)code width:(int)codeWidth
height:(int)codeHeight type:(int)codeType ForegroundColor:(UIColor
*)ForegroundColor BackgroundColor:(UIColor *)BackgroundColor
ErrorCorrectionLevel:(NSString *)ErrorCorrectionLevel
block:(void(^)(UIImage *,NSString *))block;
函数描述:生成自定义颜色 纠错级别码
输入参数:(NSString *)code 要生成的码内容
输入参数:width:(int)codeWidth 码宽
输入参数:heigh:(int)codeHeight 码高
输入参数:type:(int)codeType 码格式
输入参数:(UIColor *)ForegroundColor前景色
输入参数:(UIColor *)BackgroundColor背景色
输入参数:(NSString *)ErrorCorrectionLevel 纠错级别
0:QR码,1:GM,3:汉信,4:龙贝码,5:DM码
输入参数:block:(void(^)(UIImage *,NSString *))block 回调代码块UIImage *:生成码图 NSString *:错误信息
返回值:void
**********************************************************/
[_encodeSDK encode:code width:200 height:200 type:0 ForegroundColor: [UIColor redColor] BackgroundColor: [UIColor whiteColor] ErrorCorrectionLevel: @"M" block:^(UIImage * img, NSString *error) {
if (error) {
//生成码错误信息
Toast *toast = [[Toast alloc] initWithText:error superView:weakSelf.view];
[toast show];
}else{
_imgView.image = img;
}
}];

2.6.3安全筛选

1、定义成员变量

SDKFilter *_safeFilter;

2、初始化成员变量

_safeFilter = [[SDKFilter alloc] initWithKey:APP_KEY];

3、实现过滤

/****************************************************
函数名称:- (void)wordsFilter:(NSString *)code filterBlock:(void(^)(FilterResult *))filterBlock;
函数描述:过滤字符
输入参数:(NSString *)keystr 开放平台申请的key
输入参数:filterBlock:(void(^)(FilterResult *))filterBlock;安全过滤回调代码块(FilterResult *)安全过滤结果
输出参数:Null
返回值:void
******************************************************/
[_safeFilter wordsFilter:scanResult.content filterBlock:^(FilterResult *result) {
}];