KB: 121050
·
更新时间:2019-06-17 17:19:45
SDK初始化接口checkGatewayVerifyEnableSDK预取号接口getLoginNumberWithTimeoutSDK登录Token接口getLoginTokenWithControllerAPI取号接口getLoginTokenWithController接口默认包含预取号接口的调用,所以授权页面唤起时间偏慢些,如果先调用getLoginNumberWithTimeout接口,但是业务方得保障getLoginNumberWithTimeout回调成功后,再调用getLoginTokenWithController接口,授权页面唤起时间就偏快
阿里通信号码认证服务iOS SDK目前主要提供功能:
AuthToken接口(支持移动,电信,联通三大运营商),是请求认证的凭证,可自定义超时时间,默认3.0 s,单位 s;LoginNumber接口(支持移动,电信,联通三大运营商),是预取号缓存接口,为LoginToken接口缓存前置条件,授权页唤起更快;LoginToken接口(支持移动,电信,联通三大运营商),是请求登录的凭证,可自定义超时时间,默认3.0 s,单位 s;目前只提供静态库
.framework形式。
App项目中,需要操作如下:
Targets->General->Linked Frameworks and Libraries中添加主库,ATAuthSDK.framework;
Targets->BuildSettings中,设置Enable BitCode为NO,Other Linker Flags增加-ObjC,一定要添加此选项,注意是大写C,不是小写c,否则工程运行起来会crash!!;

由于某运营商还存在http请求,所以请确保Targets->Info中ATS开关已开启,并设置为YES;
主项目右键添加下ATAuthSDK.framework中ATAuthSDK.bundle和TYRZResource.bundle资源文件,否则一键登录授权页面图片或icon显示不出来;
/* * 函数名:sharedInstance * 参数:无 * 返回:单例 */+ (instancetype _Nonnull )sharedInstance;
/* * 函数名:getVersion * 参数:无 * 返回:字符串,sdk版本号 */- (NSString *_Nonnull)getVersion;
/* * 函数名:checkGatewayVerifyEnable * 参数:phoneNumber,手机号码,非必传,号码认证且双sim卡时必须传入待验证的手机号码!!,一键登录时设置为nil即可 * 返回:BOOL值,YES表示网关认证所需的蜂窝数据网络已开启,NO表示未开启,只有YES才能保障后续服务 */- (BOOL)checkGatewayVerifyEnable:(NSString *_Nullable)phoneNumber;
/* * 函数名:getLoginNumberWithTimeout,一键登录预取号 * 参数: timeout:接口超时时间,单位s,默认3.0s,值为0.0时采用默认超时时间 * 返回:字典形式 * resultCode:6666-成功,5555-超时,4444-失败,3344-参数异常,2222-无网络,1111-无SIM卡,6668-登录按钮事件,6669-切换到其他方式按钮事件 * msg:文案或错误提示 */
- (void)getLoginNumberWithTimeout:(NSTimeInterval )timeout complete:(void (^_Nullable)(NSDictionary * _Nonnull resultDic))complete;
/* * 函数名:getLoginTokenWithController,一键登录token * 参数: vc:当前vc容器,用于一键登录授权页面切换 model:自定义授权页面选项,可为nil,采用默认的授权页面,具体请参考TXCustomModel.h文件 timeout:接口超时时间,单位s,默认3.0s,值为0.0时采用默认超时时间 * 返回:字典形式 * resultCode:6666-成功,5555-超时,4444-失败,3344-参数异常,2222-无网络,1111-无SIM卡,6668-登录按钮事件,6669-切换到其他方式按钮事件 * token:一键登录token * msg:文案或错误提示 */
- (void)getLoginTokenWithController:(UIViewController *_Nonnull)vc model:(TXCustomModel *_Nullable)model timeout:(NSTimeInterval )timeout complete:(void (^_Nullable)(NSDictionary * _Nonnull resultDic))complete;
resultCode说明msg文案,一般是运营商的异常 // 1. 初始化接口,判断环境是否支持一键登录(参数为nil),为YES,才能执行2步骤 self.isEnable = [[TXCommonHandler sharedInstance] checkGatewayVerifyEnable:nil];
// 2. 预取号缓存,便于授权页面迅速拉起,0等待 __weak TXNumberCheckViewController *weakSelf = self; [[TXCommonHandler sharedInstance] getLoginNumberWithTimeout:0.0 complete:^(NSDictionary * _Nonnull resultDic) { NSString *code = [resultDic valueForKey:@"resultCode"]; NSString *msg = [resultDic valueForKey:@"msg"];
dispatch_async(dispatch_get_main_queue(), ^{ if ([code isEqualToString:TX_Auth_Result_Success]) { NSLog(@"getLoginNumberWithTimeout success"); weakSelf.resultTextView0.text = @"预取号成功";
// 3.1 拉起授权页面 TXCustomModel *modelNew = [[TXCustomModel alloc] init]; [[TXCommonHandler sharedInstance] getLoginTokenWithController:self model:modelNew timeout:self.time complete:^(NSDictionary * _Nonnull resultDic) {
// 具体参考非缓存版本代码;
};
} else { NSLog(@"getLoginNumberWithTimeout fail,resultDic = %@",resultDic); weakSelf.resultTextView0.text = [NSString stringWithFormat:@"预取号失败,%@",msg]; } }); }];
(3步骤,之前要确保getLoginNumberWithTimeout接口成功回调,可以block嵌套调用,也可以分开调用!!) // 3.2 拉起授权页面 TXCustomModel *modelNew = [[TXCustomModel alloc] init]; [[TXCommonHandler sharedInstance] getLoginTokenWithController:self model:modelNew timeout:self.time complete:^(NSDictionary * _Nonnull resultDic) { // 具体参考非缓存版本代码; };
self.isEnable = [[TXCommonHandler sharedInstance] checkGatewayVerifyEnable:nil];if (!self.isEnable) { self.resultTextView.text = @"设备无移动数据网络 或 获取供应商信息失败"; return;}
// 2. 获取登录token,用于3步骤登录取号接口参数__weak TXNumberCheckViewController *weakSelf = self;
// 授权页面属性定制TXCustomModel *modelNew = [[TXCustomModel alloc] init];
modelNew.navColor = UIColor.whiteColor;modelNew.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:@{NSForegroundColorAttributeName : UIColor.blackColor,NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];//modelNew.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:@{NSForegroundColorAttributeName : UIColorFromHex(0x333333),NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];//UIBarButtonItem *moreControl = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_nav_back_light"] style:UIBarButtonItemStylePlain target:self action:@selector(showMoreAction:)];UIBarButtonItem *moreControl = [[UIBarButtonItem alloc] initWithTitle:@"更多" style:UIBarButtonItemStylePlain target:self action:@selector(showMoreAction:)]; moreControl.tintColor = UIColor.grayColor; modelNew.navMoreControl = moreControl;
//modelNew.logoImage = [self imageWithColor:UIColor.orangeColor size:CGSizeMake(300.0, 300.0) isRoundedCorner:YES];modelNew.logoImage = [UIImage imageNamed:@"altx_logo"];modelNew.logoIsHidden = NO;modelNew.logoWidth = 200;modelNew.logoHeight = 90.0;modelNew.logoTopOffetY = self.ratio * 32.0;
modelNew.sloganIsHidden = NO;modelNew.sloganText = [[NSAttributedString alloc] initWithString:@"一键登录slogan文案" attributes:@{NSForegroundColorAttributeName : UIColor.orangeColor,NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];modelNew.sloganTopOffetY = self.ratio * 150.0;
//modelNew.numberColor = UIColor.orangeColor;//modelNew.numberSize = 20.0;//modelNew.numberTopOffetY = self.ratio * 200.0;
//UIImage *normalImage = [self imageWithColor:UIColor.orangeColor size:CGSizeMake(300.0, 45.0) isRoundedCorner:YES];//UIImage *disableImage = [self imageWithColor:UIColor.grayColor size:CGSizeMake(300.0, 45.0) isRoundedCorner:YES];//UIImage *lightedImage = [self imageWithColor:UIColor.greenColor size:CGSizeMake(300.0, 45.0) isRoundedCorner:YES];//modelNew.loginBtnBgImgs = @[normalImage,disableImage,lightedImage];modelNew.loginBtnTitle = @"一键登录";modelNew.loginBtnTitleColor = UIColor.whiteColor;modelNew.loginBtnTopOffetY = self.ratio * 270;
modelNew.privacyOne = @[@"流量App使用方法1",@"https://www.taobao.com/"];modelNew.privacyTwo = @[@"流量App使用方法2",@"https://www.baidu.com/"];modelNew.privacyColors = @[UIColor.darkTextColor,UIColor.blueColor];modelNew.privacyBottomOffetY = self.ratio * 15.0;//modelNew.checkBoxIsChecked = YES;//UIImage *checkedImg = [self imageWithColor:UIColor.orangeColor size:CGSizeMake(45.0, 45.0) isRoundedCorner:NO];//UIImage *unCheckedImg = [self imageWithColor:UIColor.grayColor size:CGSizeMake(45.0, 45.0) isRoundedCorner:NO];//modelNew.checkBoxImages = @[unCheckedImg,checkedImg];
modelNew.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"切换到其他方式" attributes:@{NSForegroundColorAttributeName : UIColor.blueColor,NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];modelNew.changeBtnIsHidden = NO;modelNew.changeBtnTopOffetY = self.ratio * 344;
modelNew.customViewBlock = ^(UIView * _Nonnull superCustomView) { UIView *otherView = [[UIView alloc] initWithFrame:CGRectMake(40, self.ratio * 430, TX_SCREEN_WIDTH - 2 * 40, self.ratio * 80)]; otherView.backgroundColor = UIColor.lightGrayColor;
[superCustomView addSubview:otherView];};
[[TXCommonHandler sharedInstance] getLoginTokenWithController:self model:modelNew timeout:self.time complete:^(NSDictionary * _Nonnull resultDic) {
dispatch_async(dispatch_get_main_queue(), ^{ NSString *code = [resultDic valueForKey:@"resultCode"]; if ([code isEqualToString:TX_Auth_Result_Success]) { // 授权页面成功唤起 } else if ([code isEqualToString:TX_Login_SSO_Action]) { // 授权页面销毁 [weakSelf dismissViewControllerAnimated:YES completion:nil];
NSString *token = [resultDic valueForKey:@"token"]; // 3.成功,请求业务服务端API,进行号码获取 } else if ([code isEqualToString:TX_Login_Change_Action]) { // 授权页面销毁 [weakSelf dismissViewControllerAnimated:YES completion:nil];
// 4.切换账号,可切换到业务方自己的认证方法 } else { // 授权页面销毁 [weakSelf dismissViewControllerAnimated:YES completion:nil];
// 5.失败,切换到业务方自己的认证方法 } });}];
iOS问题checkGatewayVerifyEnable一直返回NO?[NSBundle mainBundle].localizedInfoDictionary语句,如果不为nil,则有国际本地化逻辑,这样的情况,目前有两种方法修复:1,如果.strings文件内容为空且无用,删除即可;2,如果.strings文件必须要使用,则需要在主工程中所有.strings文件中增加CFBundleIdentifier = "bundleId名称";
公司名称:上海德诚网联网络技术服务有限公司
客服热线:021-61958165
联系邮箱:wangt@netlink.net.cn
举报邮箱:jubao@netlink.net.cn
地址:上海市闵行区东兰路320号2号楼201室