阿里云的一键登录的集成文档就是一个大大的坑,demo是也是一个小坑。
文档完全对不上授权SDK,demo你用了运行没有问题,但是你把它的模拟网络请求后台token请求接入工程使用就闪退了,当然它毕竟是模拟。然而文档只是说登录授权页面可以修改,但是无论是文档还是demo都没有具体说明怎么修改授权页面,你说坑不坑。我琢磨了两天才从SDK头文件里找到修改授权页面的方法。
注册请求
NSString *authSDKInfo = [[NSUserDefaults standardUserDefaults] objectForKey:PNSATAUTHSDKINFOKEY]; if (!authSDKInfo || authSDKInfo.length == 0) { authSDKInfo = PNSATAUTHSDKINFO; } [PNSHttpsManager requestATAuthSDKInfo:^(BOOL isSuccess, NSString * _Nonnull authSDKInfo) { if (isSuccess) { [[NSUserDefaults standardUserDefaults] setObject:authSDKInfo forKey:PNSATAUTHSDKINFOKEY]; } }]; [[TXCommonHandler sharedInstance] setAuthSDKInfo:authSDKInfo complete:^(NSDictionary * _Nonnull resultDic) { NSLog(@"设置秘钥结果:%@", resultDic); }];
这个是调用授权的代码:
@weakify(self); //环境检查,异步返回 [[TXCommonHandler sharedInstance] checkEnvAvailableWithAuthType:PNSAuthTypeLoginToken complete:^(NSDictionary * _Nullable resultDic) { @strongify(self); NSLog(@"环境检查返回:%@", resultDic); // UINavigationController *navigationController = self.navigationController; self.isCanUseOneKeyLogin = [PNSCodeSuccess isEqualToString:[resultDic objectForKey:@"resultCode"]]; DYMobileAuthEntity *mobileAuthEntity1 = [DYMobileAuthEntity mj_objectWithKeyValues:resultDic]; if (self.isCanUseOneKeyLogin == YES) { TXCustomModel *model = [PNSBuildModelUtils buildModelWithButton1Title:@"切换其他手机号" target1:self selector1:@selector(gotoVerificationCodeLoginPage)]; // TXCustomModel *model = [PNSBuildModelUtils buildModelWithStyle:PNSBuildModelStylePortrait // button1Title:@"切换其他手机号" // target1:self // selector1:@selector(gotoSmsControllerAndShowNavBar) // button2Title:@"" // target2:self // selector2:@selector(gotoSmsControllerAndHiddenNavBar)]; model.backgroundColor = BGColorHex(FAFAFA); model.navColor = BGColorHex(FAFAFA); NSString *textString = @""; model.navTitle = [[NSAttributedString alloc]initWithString:textString attributes:@{NSForegroundColorAttributeName:DEFAULT_TITLE_FRONT_COLOR,NSFontAttributeName:BGMediumFont(22)}]; model.navBackImage = [UIImage imageNamed:@"navbar_icon_back"]; self.customModel = model; // //设置不起作用 // model.navTitleFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) { // @strongify(self); // // return CGRectMake(frame.origin.x, 15, frame.size.width, frame.size.height); // }; // model.sloganTopOffetY = 158.0; model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) { return CGRectMake(frame.origin.x, 158.0, frame.size.width, frame.size.height); }; model.numberColor = DEFAULT_TITLE_FRONT_COLOR; model.numberFont = BGBoldFont(25); // model.numberTopOffetY = 120.0; model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) { return CGRectMake(frame.origin.x, 120.0, frame.size.width, frame.size.height); }; model.loginBtnText = [[NSAttributedString alloc]initWithString:@"同意并协助登录" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:BGMediumFont(15)}]; UIImage *loginImage = [UIImage imageNamed:@"icon_login"]; model.loginBtnBgImgs = @[loginImage,loginImage,loginImage]; // model.loginBtnTopOffetY = 212.0; // model.loginBtnHeight = 45.0; // model.loginBtnLRPadding = (FULL_WIDTH - 295)/2.0; model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) { return CGRectMake((FULL_WIDTH - 295)/2.0, 212.0, 295, 45); }; [[TXCommonHandler sharedInstance] getLoginTokenWithTimeout:3.0 controller:self model:model complete:^(NSDictionary * _Nonnull resultDic) { @strongify(self); NSLog(@"为后面授权页拉起加个速,加速结果:%@", resultDic); DYMobileAuthEntity *mobileAuthEntity = [DYMobileAuthEntity mj_objectWithKeyValues:resultDic]; if(mobileAuthEntity && [mobileAuthEntity isKindOfClass:[DYMobileAuthEntity class]] && !isCommonUnitEmptyString(mobileAuthEntity.resultCode)) { if([PNSCodeSuccess isEqualToString:mobileAuthEntity.resultCode]) { self.model.accessToken = mobileAuthEntity.token; [self excuteMemberAccountLoginByTelCommand]; } else if([PNSCodeLoginControllerClickLoginBtn isEqualToString:mobileAuthEntity.resultCode] && !(mobileAuthEntity.isChecked)) { [[BITNoticeView currentNotice] showErrorNotice:@"请同意认证服务条款、龙莱用户协议以及隐私政策"]; } } }];
修改授权页面的协议增加按钮和标签:
+ (TXCustomModel *)buildModelWithButton1Title:(NSString *)button1Title target1:(id)target1 selector1:(SEL)selector1 { TXCustomModel *model = [[TXCustomModel alloc] init]; model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait; // model.navColor = [UIColor orangeColor]; // NSDictionary *attributes = @{ // NSForegroundColorAttributeName : [UIColor whiteColor], // NSFontAttributeName : [UIFont systemFontOfSize:20.0] // }; // model.navTitle = [[NSAttributedString alloc] initWithString:@"一键登录" attributes:attributes]; // model.navBackImage = [UIImage imageNamed:@"icon_nav_back_light"]; // model.logoImage = [UIImage imageNamed:@"taobao"]; // model.changeBtnIsHidden = YES; model.checkBoxImages = @[[UIImage imageNamed:@"icon_select_agreement"],[UIImage imageNamed:@"icon_select_agreement_select"]]; model.privacyOne = @[@"龙莱用户协议", @"https://www.taobao.com"]; model.privacyTwo = @[@"隐私政策", @"https://www.baidu.com/"]; model.privacyConectTexts = @[@"、", @",", @"以及"]; model.privacyColors = @[DEFAULT_TITLE_SUPER_FRONT_COLOR, BGColorHex(64B7FF)]; model.checkBoxWH = 15.0; model.privacyPreText = @"使用手机号码登录并同意"; model.privacyNavBackImage = [UIImage imageNamed:@"navbar_icon_back"]; UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.text = @"本机号码一键登录"; titleLabel.textColor = DEFAULT_TITLE_FRONT_COLOR; titleLabel.font = BGMediumFont(22); titleLabel.textAlignment = NSTextAlignmentCenter; UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem]; [button1 setTitle:button1Title forState:UIControlStateNormal]; [button1 addTarget:target1 action:selector1 forControlEvents:UIControlEventTouchUpInside]; [button1.titleLabel setFont:[UIFont systemFontOfSize:14]]; [button1 setTitleColor:DEFAULT_TITLE_FRONT_COLOR forState:UIControlStateNormal]; button1.backgroundColor = [UIColor clearColor]; model.customViewBlock = ^(UIView * _Nonnull superCustomView) { [superCustomView addSubview:titleLabel]; [superCustomView addSubview:button1]; }; model.customViewLayoutBlock = ^(CGSize screenSize, CGRect contentViewFrame, CGRect navFrame, CGRect titleBarFrame, CGRect logoFrame, CGRect sloganFrame, CGRect numberFrame, CGRect loginFrame, CGRect changeBtnFrame, CGRect privacyFrame) { titleLabel.frame = CGRectMake(0, 15, screenSize.width, 22); button1.frame = CGRectMake(0, 285, screenSize.width, 14); }; model.changeBtnIsHidden = YES; return model; }