我接入这个的时候,网上可用代码找不到,sdk文档也写的比较坑,各类错别字就不说了。json
先说说比较坑的:1. 这个官方sdk带的demo下载下来是没法运行的,须要手动替换里面的sdk包,由于demo里面的不是release模式。网络
2. 而后换了sdk以后发现ATAuthSDK.bundle和TYRZResource.bundle这两个文件找不到,须要手动从release文件将他们拖出来放到工程里面。app
到这里demo能运行了。async
好接下来,须要在阿里云后台注册app,填好bundelid就好了。在本身工程里面也要按照上面的步骤将sdk导入,其余配置按照接入文档操做便可。ide
代码部分:阿里云
第一步:首次判断当前设备网络环境,有没有运营商网络 spa
self.isEnable = [[TXCommonHandler sharedInstance] checkSyncGatewayVerifyEnable:nil];//判断当前设备是否有移动运营商网络code
if (!self.isEnable) {orm
[self.view hideToastActivity];token
[KPToast showToastWithMessage:@"设备无移数据网络 或 获获取供应商信息失败"];
return;
}else{
[self getLoginMobileAndToken];
}
第二部:调用阿里云sdk
#pragma mark ------ 调用一键登陆sdk
- (void)getLoginMobileAndToken{
TXCustomModel *modelNew = [[TXCustomModel alloc] init];
modelNew.navTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName : UIColor.blackColor,NSFontAttributeName : [UIFont systemFontOfSize:24.0]}];
modelNew.navBackImage = [UIImage imageNamed:@"icon_nav_back_gray"];
//logo
modelNew.logoImage = [UIImage imageNamed:@"pf_login_icon"];
modelNew.logoIsHidden = NO;
modelNew.logoWidth = 200;
modelNew.logoHeight = 90.0;
modelNew.logoTopOffetY = self.ratio * 50.0;
//xxxx运营商提供认证服务
modelNew.sloganIsHidden = NO;
modelNew.sloganText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@提供号码认证服务",[TXCommonUtils getCurrentCarrierName]] attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0x333333),NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];
modelNew.sloganTopOffetY = self.ratio * 170.0;
//手机号码
modelNew.numberColor = UIColorFromRGB(0x333333);
modelNew.numberFont = [UIFont systemFontOfSize:20.0];
modelNew.numberTopOffetY = self.ratio * 200.0;
//登陆按钮
modelNew.loginBtnText = [[NSAttributedString alloc] initWithString:@"一键登陆" attributes:@{NSForegroundColorAttributeName : UIColor.whiteColor,NSFontAttributeName : [UIFont systemFontOfSize:20.0]}];
modelNew.loginBtnTopOffetY = self.ratio * 270;
modelNew.loginBtnHeight = 50.0;
modelNew.loginBtnLRPadding = 18.0;
// modelNew.loginBtnBgImgs = @[@"pf_loginBtn_bac",@"pf_loginBtn_bac",@"pf_loginBtn_bac"];
//底部协议
modelNew.privacyColors = @[UIColor.lightGrayColor,UIColorFromRGB(0x3c99fa)];
modelNew.privacyBottomOffetY = self.ratio * 25.0;
modelNew.privacyAlignment = NSTextAlignmentCenter;
modelNew.privacyLRPadding = 8.0;
modelNew.privacyFont = [UIFont systemFontOfSize:12.0];
modelNew.checkBoxIsHidden = NO;
modelNew.checkBoxIsChecked = YES;
modelNew.checkBoxWH = 15.0;
//切换到其余方式
modelNew.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName : UIColor.orangeColor,NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];
modelNew.changeBtnIsHidden = YES;//隐藏
modelNew.changeBtnTopOffetY = self.ratio * 344;
__weak KPLoginNewViewController *weakSelf = self;
[[TXCommonHandler sharedInstance] getLoginTokenWithController:self model:modelNew timeout:self.time complete:^(NSDictionary * _Nonnull resultDic) {
[self.view hideToastActivity];
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"];
NSLog(@"运营商token===%@",token);
// 能够去请求服务端getMobile接口,用token换取手机号码啦
}else{
[weakSelf.view makeToast:@"登陆失败"];
}
} failure:^(NSString *errorStr, NSString *errorCode) {
[weakSelf.view makeToast:@"登陆失败"];
}];
}else if ([code isEqualToString:TX_Login_Change_Action]) {//切换到其余方式
}else if ([code isEqualToString:TX_Login_Return_Action] || [code isEqualToString:TX_Login_AuthPage_Show_Success]) {
}else {
[weakSelf dismissViewControllerAnimated:YES completion:nil];
NSLog(@"getLoginTokenWithController fail,resultDic = %@",resultDic);
[KPToast showToastWithMessage:@"获取登陆Token失败"];
}
#ifdef DEBUG
NSLog(@"getLoginTokenWithController,resultDic = %@",[self jsonStrFromDic:resultDic]);
#endif
});
}];
}
代码就这么多,阿里云第三方页面能够高度定制,灵活更改,有不懂的联系553502397@qq.com