項目中使用的是阿里的SDK,具體可以看阿里的文檔:iOS 客戶端接入
我記錄下項目中的代碼部分:
項目中使用的是授權(quán)頁全屏模式,在需要彈授權(quán)頁的控制器導入頭文件:
#import <ATAuthSDK/ATAuthSDK.h>
然后定義一個屬性:
///是否可以一鍵注冊
@property (nonatomic, assign) BOOL isCanUseOneKey;
以下為代碼部分:
//開始狀態(tài)置為YES,默認當前環(huán)境可以使用一鍵登錄
self.isCanUseOneKey = YES;
__weak typeof(self) weakSelf = self;
//環(huán)境檢查,異步返回
[[TXCommonHandler sharedInstance] checkEnvAvailableWithAuthType:PNSAuthTypeLoginToken
complete:^(NSDictionary * _Nullable resultDic) {
NSLog(@"環(huán)境檢查返回:%@", resultDic);
weakSelf.isCanUseOneKey = [PNSCodeSuccess isEqualToString:[resultDic objectForKey:@"resultCode"]];
if (weakSelf.isCanUseOneKey == NO) {//不能使用一鍵注冊時跳轉(zhuǎn)其他方式注冊頁面
//其他注冊方式
} else {
//設置授權(quán)頁UI
TXCustomModel *model = [[TXCustomModel alloc] init];
model.supportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
model.navColor = White_Color;
NSDictionary *attributes = @{
NSForegroundColorAttributeName : Black_Color,
NSFontAttributeName : [UIFont systemFontOfSize:20.0]
};
model.navTitle = [[NSAttributedString alloc] initWithString:@"一鍵注冊" attributes:attributes];
model.navBackImage = [UIImage imageNamed:@"icon_nav_back_light"];
model.logoImage = [UIImage imageNamed:@"applogo_160"];
model.loginBtnText = [[NSAttributedString alloc] initWithString:@"本機號碼一鍵注冊" attributes:@{NSForegroundColorAttributeName:White_Color,NSFontAttributeName:[UIFont systemFontOfSize:18]}];
UIImage *canImage = [UIImage imageNamed:@"home_screen_register_button"];
UIImage *NOimage = [[UIImage alloc] changeImage:canImage tintColor:UIColorFromHex(0xDCDCDC)];
model.loginBtnBgImgs = @[canImage,NOimage,canImage];
model.changeBtnIsHidden = NO;
model.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"其他手機號注冊" attributes:@{NSForegroundColorAttributeName:LightGray_Color,NSFontAttributeName:[UIFont systemFontOfSize:14]}];
model.autoHideLoginLoading = NO;
model.sloganIsHidden = YES;
model.checkBoxWH = 24;
model.checkBoxImages = @[[UIImage imageNamed:@"Icons_checkoff"],[UIImage imageNamed:@"Icons_checkon"]];
NSURL *file = [[NSUserDefaults standardUserDefaults] URLForKey:yinsiPath];
NSURL *file1 = [[NSUserDefaults standardUserDefaults] URLForKey:yonghuPath];
NSString *string = file.absoluteString;
NSString *string1 = file1.absoluteString;
//自己的協(xié)議,加載服務器下載下來的
model.privacyOne = @[@"隱私政策",string];
model.privacyTwo = @[@"用戶協(xié)議",string1];
model.presentDirection = PNSPresentationDirectionRight;
//調(diào)整UI
model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
frame.size.width = 98;
frame.size.height = 99.5;
frame.origin.x = (superViewSize.width - 98) * 0.5;
frame.origin.y = superViewSize.height*1/5 ;
return frame;
};
model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
frame.size.width = 240;
frame.size.height = 48;
frame.origin.x = (superViewSize.width - 240) * 0.5;
frame.origin.y = superViewSize.height*1/5 + 99.5 + 10 + 20 +20;
return frame;
};
model.changeBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
frame.size.width = 240;
frame.size.height = 48;
frame.origin.x = (superViewSize.width - 240) * 0.5;
frame.origin.y = superViewSize.height*1/5 + 99.5 + 10 + 20 +20 + 48;
return frame;
};
__weak typeof(self) weakSelf = self;
[[TXCommonHandler sharedInstance] getLoginTokenWithTimeout:3.0
controller:self
model:model
complete:^(NSDictionary * _Nonnull resultDic) {
NSString *code = [resultDic objectForKey:@"resultCode"];
if ([PNSCodeLoginControllerPresentSuccess isEqualToString:code]) {
// [ProgressHUD showSuccess:@"彈起授權(quán)?成功"];
} else if ([PNSCodeLoginControllerClickCancel isEqualToString:code]) {
// [ProgressHUD showSuccess:@"點擊了授權(quán)?的返回"];
} else if ([PNSCodeLoginControllerClickChangeBtn isEqualToString:code]) {
// [ProgressHUD showSuccess:@"點擊切換其他注冊?式按鈕"];
dispatch_async(dispatch_get_main_queue(), ^{//注銷授權(quán)頁,建議用此方法,對于移動卡授權(quán)頁的消失會清空一些數(shù)據(jù)
[[TXCommonHandler sharedInstance] cancelLoginVCAnimated:YES complete:nil];
});
//其他注冊方式
} else if ([PNSCodeLoginControllerClickLoginBtn isEqualToString:code]) {
if ([[resultDic objectForKey:@"isChecked"] boolValue] == YES) {
//[ProgressHUD showSuccess:@"點擊了登錄按鈕,check box選 中,SDK內(nèi)部接著會去獲取登陸Token"];
} else {
// [ProgressHUD showSuccess:@"點擊了登錄按鈕,check box選 中,SDK內(nèi)部不會去獲取登陸Token"];
}
} else if ([PNSCodeLoginControllerClickCheckBoxBtn isEqualToString:code]) {
// [ProgressHUD showSuccess:@"點擊check box"];
} else if ([PNSCodeLoginControllerClickProtocol isEqualToString:code]) {
// [ProgressHUD showSuccess:@"點擊了協(xié)議富?本"];
} else if ([PNSCodeSuccess isEqualToString:code]) {
//點擊按鈕獲取注冊Token成功回調(diào)
NSString *token = [resultDic objectForKey:@"token"];
QYLog(@"一鍵注冊token = %@",token);
//下?拿Token去自己的服務器換?機號
} else {
[[TXCommonHandler sharedInstance] hideLoginLoading];
[Util toastMessage:@"請檢查是否插入SIM卡并打開蜂窩網(wǎng)絡" delay:2.0];
}
}];
};
}];
到這里一鍵注冊代碼部分就完成了。
授權(quán)頁的UI絕大多數(shù)是支持更改的,主要看自己項目需求然后在對照屬性去更改。