在Podfile中
#一鍵登錄(極光)
pod 'JCore', '~> 2.4.0-noidfa' # 不含廣告標(biāo)識(shí)符,以便Apple審核
pod 'JVerification'
相關(guān)鏈接:
(1)一鍵登錄對(duì)應(yīng)錯(cuò)誤碼的處理辦法
https://community.jiguang.cn/question/418644
(2)iOS 一鍵登錄功能實(shí)現(xiàn)
http://www.itdecent.cn/p/0a568ec3cbbd
(3)極光文檔
https://docs.jiguang.cn/jverification/client/ios_api/
1、在APPdelegate.m中
導(dǎo)入頭文件:#import "JVERIFICATIONService.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 啟動(dòng)頁(yè)延時(shí):1秒
[NSThread sleepForTimeInterval:0.5];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
self.mainTabBarVC = [[LRTabBarViewController alloc] init];
self.window.rootViewController = self.mainTabBarVC;
[self.window makeKeyAndVisible];
// 集成極光認(rèn)證SDK(一鍵登錄)
//如需使用 IDFA 功能請(qǐng)?zhí)砑哟舜a并在初始化配置類中設(shè)置 advertisingId
// NSString *idfaStr = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
JVAuthConfig *config = [[JVAuthConfig alloc] init];
config.appKey = @"fd6089c4c155a4d22c2883c8";
// config.advertisingId = idfaStr;
config.authBlock = ^(NSDictionary *result) {
NSLog(@"初始化結(jié)果 result:%@", result);
};
[JVERIFICATIONService setupWithConfig:config];
/*!
* @abstract 設(shè)置是否打印sdk產(chǎn)生的Debug級(jí)log信息, 默認(rèn)為NO(不打印log)
*
* SDK 默認(rèn)開啟的日志級(jí)別為: Info. 只顯示必要的信息, 不打印調(diào)試日志.
*
* 請(qǐng)?jiān)赟DK啟動(dòng)后調(diào)用本接口,調(diào)用本接口可打開日志級(jí)別為: Debug, 打印調(diào)試日志.
* 請(qǐng)?jiān)诎l(fā)布產(chǎn)品時(shí)改為NO,避免產(chǎn)生不必要的IO
*/
[JVERIFICATIONService setDebug:NO];
// BOOL isSetupClient = [JVERIFICATIONService isSetupClient];
// if (isSetupClient) {
// //初始化完成,可以進(jìn)行后續(xù)操作
// }
return YES;
}
2、在登錄頁(yè)
//
// LoginViewCTRL.m
//
// Created by Ger on 2021/6/16.
//
#import "LoginViewCTRL.h"
#import "CheckUserAgreementCTRL.h"
#import "QuickLoginSucceedView.h"
#import "RegisterViewCTRL.h"
#import "JVERIFICATIONService.h"
@interface LoginViewCTRL ()<UITextViewDelegate, UITextFieldDelegate>
@property (nonatomic, strong) UIButton *backBut;
@property (nonatomic, strong) UIButton *registerBut; // 注冊(cè)
@property (nonatomic, strong) UIImageView *logoImg;
@property (nonatomic, strong) UILabel *tipsL;
@property (nonatomic, strong) UILabel *tipsLL;
@property (nonatomic, strong) UILabel *phoneL;
@property (nonatomic, strong) UITextField *phoneTextField;
@property (nonatomic, strong) UILabel *paswordL;
@property (nonatomic, strong) UITextField *passwordTextField;
@property (nonatomic, strong) UIButton *resetPasswordBut; // 重置密碼
@property (nonatomic, strong) UIButton *loginBut;
@property (nonatomic, strong) UITextView *agreementTextView;
@property (nonatomic, strong) UIButton *agreeBut; // 是否同意協(xié)議
@property (nonatomic, strong) UITextView *loginTextView; // 去賬號(hào)、密碼 登錄
@property (nonatomic, strong) UITextView *registerTextView; // 去賬號(hào)、密碼、驗(yàn)證碼 注冊(cè)
@property (nonatomic, strong) QuickLoginSucceedView *quickLoginView;
@property (nonatomic, strong) NSString *token; // 極光一鍵登錄 手機(jī)號(hào)校驗(yàn)token
@property (nonatomic, strong) NSString *loginToken; // 授權(quán)一鍵登錄 loginToken
@property (nonatomic, strong) JVUIConfig *config; // 一鍵登錄頁(yè)面的UI布局
@end
@implementation LoginViewCTRL
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
if(![JVERIFICATIONService checkVerifyEnable]) {
NSLog(@"當(dāng)前網(wǎng)絡(luò)環(huán)境不支持認(rèn)證!"); // code = 2016 時(shí),可能是沒有打開 “移動(dòng)網(wǎng)路”,wifi無論打開與否,“移動(dòng)網(wǎng)絡(luò)”都必須在打開的情況下,才會(huì)獲取token
[KAlertViewFactory showToastWithMessage:@"當(dāng)前網(wǎng)絡(luò)環(huán)境不支持,請(qǐng)打開移動(dòng)網(wǎng)絡(luò)再次嘗試"];
[self setupUINormalView]; // 賬號(hào)、密碼登錄
return;
}
// 獲取手機(jī)號(hào)校驗(yàn)token
// 說明:開發(fā)者可以通過SDK獲取token接口的回調(diào)信息來選擇驗(yàn)證方式,若成功獲取到token則可以繼續(xù)使用極光認(rèn)證進(jìn)行號(hào)碼驗(yàn)證;若獲取token失敗,需要換用短信驗(yàn)證碼等方式繼續(xù)完成驗(yàn)證。
[JVERIFICATIONService getToken:10*1000 completion:^(NSDictionary *result) {
NSLog(@"getToken result:%@", result);
//TODO:獲取token后相關(guān)操作
NSInteger code = [[NSString stringWithFormat:@"%@", result[@"code"]] integerValue];
if (code == 2000) {
NSLog(@"獲取token成功");
self.token = result[@"token"];
if ([self.token isKindOfClass:[NSString class]] && self.token.length > 0) {
// 獲取token成功(判斷可以執(zhí)行 “一鍵登錄功能”)
[self customSetupUI];// 自定義UI布局
} else {
[self setupUINormalView];
}
} else if (code == 2001) {
NSLog(@"獲取token失敗");
[self setupUINormalView];
} else if (code == 2005) {
NSLog(@"請(qǐng)求超時(shí)");
[self setupUINormalView];
} else {
[self setupUINormalView];
}
}];
// 驗(yàn)證當(dāng)前運(yùn)營(yíng)商網(wǎng)絡(luò)是否可以進(jìn)行一鍵登錄操作,該方法會(huì)緩存取號(hào)信息,提高一鍵登錄效率。建議發(fā)起一鍵登錄前先調(diào)用此方法。
[JVERIFICATIONService preLogin:10*1000 completion:^(NSDictionary *result) {
NSLog(@"登錄預(yù)取號(hào) result:%@", result);
NSInteger code = [[NSString stringWithFormat:@"%@", result[@"code"]] integerValue];
if (code == 7000) {
NSLog(@"預(yù)取號(hào)成功");
} else if (code == 7001) {
NSLog(@"預(yù)取號(hào)失敗");
} else if (code == 7001) {
NSLog(@"取號(hào)中");
} else if (code == 6006) {
NSLog(@"預(yù)取號(hào)信息過期,請(qǐng)重新預(yù)取號(hào)");
[JVERIFICATIONService clearPreLoginCache]; // 清除預(yù)取號(hào)緩存
}
}];
}
- (void)setupUINormalView {
// 布局登錄頁(yè)面 非一鍵登錄ui
[self setupUI];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickHideKeyBoardAction)];
self.view.userInteractionEnabled = YES;
[self.view addGestureRecognizer:tap];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
- (void)setupUI {
/// 布局登錄頁(yè)面 非一鍵登錄ui
UIEdgeInsets insets = UIEdgeInsetsMake(20, 0, 0, 0);
if (@available(iOS 11.0, *)) {
insets = [UIApplication sharedApplication].keyWindow.safeAreaInsets;
}
_backBut = [UIButton buttonWithType:UIButtonTypeCustom];
[_backBut setImage:[UIImage imageNamed:@"login_X_icon"] forState:UIControlStateNormal];
[self.view addSubview:self.backBut];
[self.backBut makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset([UIScreen mainScreen].bounds.size.width/375*15 + insets.top);
make.left.mas_equalTo(self.view.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*20);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*14);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*14.5);
}];
[self.backBut addTarget:self action:@selector(clickBackPageAction) forControlEvents:UIControlEventTouchUpInside];
_registerBut = [UIButton buttonWithType:UIButtonTypeCustom];
_registerBut.backgroundColor = [UIColor whiteColor];
[_registerBut setTitle:@"注冊(cè)" forState:UIControlStateNormal];
[_registerBut setTitleColor:RGBA(20, 20, 20, 1) forState:UIControlStateNormal];
_registerBut.titleLabel.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*14 weight:UIFontWeightMedium];
[self.view addSubview:self.registerBut];
[self.registerBut makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.backBut);
make.right.mas_equalTo(self.view.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*20);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*35);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*16);
}];
[self.registerBut addTarget:self action:@selector(clickRegisterAction) forControlEvents:UIControlEventTouchUpInside];
_logoImg = [[UIImageView alloc] init];
_logoImg.image = [UIImage imageNamed:@"login_logo_icon"];
[self.view addSubview:self.logoImg];
[self.logoImg makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.backBut.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*38);
make.left.mas_equalTo(self.view.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*30);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*30);
}];
_tipsL = [[UILabel alloc] init];
_tipsL.text = @"手機(jī)號(hào)登錄";
_tipsL.textColor = RGBA(20, 20, 20, 1);
_tipsL.textAlignment = NSTextAlignmentLeft;
_tipsL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*21 weight:UIFontWeightMedium];
[self.view addSubview:self.tipsL];
[self.tipsL makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.logoImg);
make.left.mas_equalTo(self.logoImg.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*5);
}];
_tipsLL = [[UILabel alloc] init];
_tipsLL.text = @" 賬號(hào)通用";
_tipsLL.textColor = RGBA(142, 142, 142, 1);
_tipsLL.textAlignment = NSTextAlignmentLeft;
_tipsLL.numberOfLines = 0;
_tipsLL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*12 weight:UIFontWeightRegular];
[self.view addSubview:self.tipsLL];
[self.tipsLL makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.logoImg.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*12);
make.left.mas_equalTo(self.logoImg.mas_left);
make.right.mas_equalTo(self.view.mas_right).offset(20);
}];
_phoneL = [[UILabel alloc] init];
_phoneL.text = @"手機(jī)號(hào)";
_phoneL.textColor = RGBA(142, 142, 142, 1);
_phoneL.textAlignment = NSTextAlignmentLeft;
_phoneL.numberOfLines = 0;
_phoneL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*13 weight:UIFontWeightRegular];
[self.view addSubview:self.phoneL];
[self.phoneL makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.tipsLL.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*42);
make.left.mas_equalTo(self.view.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*40);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*42);
}];
_phoneTextField = [[UITextField alloc] init];
_phoneTextField.backgroundColor = [UIColor whiteColor];
_phoneTextField.textColor = RGBA(51, 51, 51, 1);
_phoneTextField.tintColor = RGBA(88, 205, 82, 1);
// _phoneTextField.placeholder = @"占位文字";
_phoneTextField.textAlignment = NSTextAlignmentLeft;
_phoneTextField.layer.masksToBounds = YES;
_phoneTextField.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*5;
self.phoneTextField.returnKeyType = UIReturnKeyDone;
_phoneTextField.clearButtonMode = UITextFieldViewModeAlways;
_phoneTextField.keyboardType = UIKeyboardTypePhonePad;
_phoneTextField.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*14 weight:UIFontWeightRegular];
self.phoneTextField.delegate = self;
[self.view addSubview:self.phoneTextField];
[self.phoneTextField makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.phoneL);
make.left.mas_equalTo(self.phoneL.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*10);
make.right.mas_equalTo(self.view.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*40);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*16);
}];
UIView *phoneSeparateView = [[UIView alloc] init];
phoneSeparateView.backgroundColor = RGBA(232, 232, 232, 1);
[self.view addSubview:phoneSeparateView];
[phoneSeparateView makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.phoneL.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*16);
make.left.mas_equalTo(self.view.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*40);
make.right.mas_equalTo(self.view.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*40);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*0.5);
}];
_paswordL = [[UILabel alloc] init];
_paswordL.text = @"密鑰碼";
_paswordL.textColor = RGBA(142, 142, 142, 1);
_paswordL.textAlignment = NSTextAlignmentLeft;
_paswordL.numberOfLines = 0;
_paswordL.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*13 weight:UIFontWeightRegular];
[self.view addSubview:self.paswordL];
[self.paswordL makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.phoneL.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*33);
make.left.mas_equalTo(self.view.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*40);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*42);
}];
NSMutableAttributedString *passwordString = [[NSMutableAttributedString alloc] initWithString:self.paswordL.text];
// 找出特定字符在整個(gè)字符串的位置的位置
NSRange normalRange = NSMakeRange([[passwordString string] rangeOfString:@"鑰"].location, [[passwordString string] rangeOfString:@"鑰"].length);
// 修改特定字符的顏色
[passwordString addAttribute:NSForegroundColorAttributeName
value:RGBA(142, 142, 142, 1)
range:[self.paswordL.text rangeOfString:self.paswordL.text]];
[passwordString addAttribute:NSForegroundColorAttributeName
value:[UIColor whiteColor]
range:normalRange];
// 修改特定字符的字體大小
// [passwordString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*12 weight:UIFontWeightBold] range:normalRange];
self.paswordL.attributedText = passwordString;
_passwordTextField = [[UITextField alloc] init];
_passwordTextField.backgroundColor = [UIColor whiteColor];
_passwordTextField.textColor = RGBA(51, 51, 51, 1);
_passwordTextField.tintColor = RGBA(88, 205, 82, 1);
// _passwordTextField.placeholder = @"占位文字";
_passwordTextField.textAlignment = NSTextAlignmentLeft;
_passwordTextField.layer.masksToBounds = YES;
_passwordTextField.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*5;
self.passwordTextField.returnKeyType = UIReturnKeyDone;
_passwordTextField.clearButtonMode = UITextFieldViewModeAlways;
_passwordTextField.keyboardType = UIKeyboardTypeDefault;
_passwordTextField.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*14 weight:UIFontWeightRegular];
self.passwordTextField.delegate = self;
[self.view addSubview:self.passwordTextField];
[self.passwordTextField makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.paswordL);
make.left.mas_equalTo(self.paswordL.mas_right).offset([UIScreen mainScreen].bounds.size.width/375*10);
make.right.mas_equalTo(self.view.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*40);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*16);
}];
UIView *passwordSeparateView = [[UIView alloc] init];
passwordSeparateView.backgroundColor = RGBA(232, 232, 232, 1);
[self.view addSubview:passwordSeparateView];
[passwordSeparateView makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.paswordL.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*16);
make.left.mas_equalTo(self.view.mas_left).offset([UIScreen mainScreen].bounds.size.width/375*40);
make.right.mas_equalTo(self.view.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*40);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*0.5);
}];
_resetPasswordBut = [UIButton buttonWithType:UIButtonTypeCustom];
_resetPasswordBut.backgroundColor = [UIColor whiteColor];
[_resetPasswordBut setTitle:@"重置密碼" forState:UIControlStateNormal];
[_resetPasswordBut setTitleColor:RGBA(142, 142, 142, 1) forState:UIControlStateNormal];
_resetPasswordBut.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; // 字體位置偏右
_resetPasswordBut.titleLabel.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*11 weight:UIFontWeightRegular];
[self.view addSubview:self.resetPasswordBut];
[self.resetPasswordBut makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(passwordSeparateView).offset([UIScreen mainScreen].bounds.size.width/375*12);
make.right.mas_equalTo(self.view.mas_right).offset(-[UIScreen mainScreen].bounds.size.width/375*40);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*55);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*14);
}];
[self.resetPasswordBut addTarget:self action:@selector(clickresetPasswordAction) forControlEvents:UIControlEventTouchUpInside];
_loginBut = [UIButton buttonWithType:UIButtonTypeCustom];
_loginBut.backgroundColor = RGBA(15, 15, 15, 1);
[_loginBut setTitle:@"登錄" forState:UIControlStateNormal];
[_loginBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_loginBut.titleLabel.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*15 weight:UIFontWeightMedium];
self.loginBut.layer.masksToBounds = YES;
self.loginBut.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*5;
[self.view addSubview:self.loginBut];
[self.loginBut makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.top.mas_equalTo(passwordSeparateView.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*60);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*315);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*43);
}];
[self.loginBut addTarget:self action:@selector(clickLoginAction) forControlEvents:UIControlEventTouchUpInside];
_agreementTextView = [[UITextView alloc] init];
_agreementTextView.text = @"我已閱讀并同意《俄語閱讀用戶服務(wù)協(xié)議》";
_agreementTextView.backgroundColor = [UIColor whiteColor];
_agreementTextView.textColor = RGBA(142, 142, 142, 1);
_agreementTextView.textAlignment = NSTextAlignmentRight;
_agreementTextView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
_agreementTextView.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*11 weight:UIFontWeightRegular];
_agreementTextView.showsVerticalScrollIndicator = NO;
_agreementTextView.scrollEnabled = NO;
_agreementTextView.editable = NO;
self.agreementTextView.delegate = self;
[self.view addSubview:self.agreementTextView];
[self.agreementTextView makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.top.mas_equalTo(self.loginBut.mas_bottom).offset([UIScreen mainScreen].bounds.size.width/375*20);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*230);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*13);
}];
[self agreementSetupHanleTextView:self.agreementTextView];
_agreeBut = [UIButton buttonWithType:UIButtonTypeCustom];
[_agreeBut setImage:[UIImage imageNamed:@"userAgreement_normal_icon"] forState:UIControlStateNormal];
[_agreeBut setImage:[UIImage imageNamed:@"userAgreement_selected_icon"] forState:UIControlStateSelected];
[self.view addSubview:self.agreeBut];
[self.agreeBut makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.agreementTextView);
make.right.mas_equalTo(self.agreementTextView.mas_left);
make.width.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*11);
}];
[self.agreeBut addTarget:self action:@selector(clickAgrreeAction) forControlEvents:UIControlEventTouchUpInside];
}
- (void)clickBackPageAction {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -- Login各種操作
- (void)clickLoginAction {
// 登錄
if (self.agreeBut.selected) {
if (self.phoneTextField.text.length == 0 ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"請(qǐng)輸入手機(jī)號(hào)" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alert show];
return;
}
if (self.passwordTextField.text.length < 6 ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"請(qǐng)輸入至少6位密碼" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alert show];
return;
}
[self loginAccount];
} else {
[KAlertViewFactory showToastWithMessage:@"請(qǐng)同意《俄語閱讀用戶服務(wù)協(xié)議》再登錄"];
}
}
- (void)clickAgrreeAction {
self.agreeBut.selected = !self.agreeBut.selected;
}
- (void)clickRegisterAction {
// 注冊(cè)
RegisterViewCTRL *registerVC = [[RegisterViewCTRL alloc] init];
registerVC.title = @"注冊(cè)";
[self.navigationController pushViewController:registerVC animated:YES];
}
- (void)clickresetPasswordAction {
// 重置密碼
RegisterViewCTRL *registerVC = [[RegisterViewCTRL alloc] init];
registerVC.title = @"重置密碼";
[self.navigationController pushViewController:registerVC animated:YES];
}
- (void)clickHideKeyBoardAction {
[self.phoneTextField resignFirstResponder];
[self.passwordTextField resignFirstResponder];
}
#pragma mark -- UITextField
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
// Return鍵
[textField resignFirstResponder];
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// 開始編輯
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
// 編輯結(jié)束
[textField resignFirstResponder];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
return YES;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
// 滑動(dòng) TableView時(shí)
[self.phoneTextField resignFirstResponder];
[self.passwordTextField resignFirstResponder];
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// 點(diǎn)擊 tableViewCell 的時(shí)候,收回鍵盤
[self.phoneTextField resignFirstResponder];
[self.passwordTextField resignFirstResponder];
return indexPath;
}
#pragma mark -- 自定義 一鍵登錄頁(yè)面布局
- (void)customSetupUI {
// 自定義一鍵登錄頁(yè)面布局
JVUIConfig *config = [[JVUIConfig alloc] init];
config.navReturnImg = [UIImage imageNamed:@"login_X_icon"];
config.agreementNavReturnImage = [UIImage imageNamed:@"back_black_icon"];
config.shouldAutorotate = YES;
config.autoLayout = YES;
config.navText = [[NSAttributedString alloc] initWithString:@"一鍵登錄認(rèn)證" attributes:@{NSForegroundColorAttributeName:RGBA(0, 0, 0, 1), NSFontAttributeName:[UIFont systemFontOfSize:18]}];
config.navDividingLineHidden = YES;
config.prefersStatusBarHidden = NO;
config.navReturnHidden = NO;
config.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//logo
config.logoImg = [UIImage imageNamed:@"login_logo_icon"];
CGFloat logoWidth = [UIScreen mainScreen].bounds.size.width/375*45;
CGFloat logoHeight = logoWidth;
JVLayoutConstraint *logoConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; // 屏幕的中間X軸,沒有偏移量
JVLayoutConstraint *logoConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterY multiplier:1 constant:-[UIScreen mainScreen].bounds.size.width/375*120]; // 屏幕的中間Y軸,向上 到該矩形的Bottom,距離120
JVLayoutConstraint *logoConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:logoWidth];
JVLayoutConstraint *logoConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:logoHeight];
config.logoConstraints = @[logoConstraintX,logoConstraintY,logoConstraintW,logoConstraintH];
config.logoHorizontalConstraints = config.logoConstraints;
// 號(hào)碼欄
JVLayoutConstraint *numberConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
JVLayoutConstraint *numberConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterY multiplier:1 constant:-[UIScreen mainScreen].bounds.size.width/375*75];
JVLayoutConstraint *numberConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:[UIScreen mainScreen].bounds.size.width/375*160];
JVLayoutConstraint *numberConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:25];
config.numberConstraints = @[numberConstraintX,numberConstraintY, numberConstraintW, numberConstraintH];
config.numberHorizontalConstraints = config.numberConstraints;
//slogan展示
JVLayoutConstraint *sloganConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
JVLayoutConstraint *sloganConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterY multiplier:1 constant:-[UIScreen mainScreen].bounds.size.width/375*50];
JVLayoutConstraint *sloganConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:160];
JVLayoutConstraint *sloganConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:20];
config.sloganConstraints = @[sloganConstraintX,sloganConstraintY, sloganConstraintW, sloganConstraintH];
config.sloganHorizontalConstraints = config.sloganConstraints;
//登錄按鈕
UIImage *login_nor_image = [UIImage imageNamed:@"loginBtn_Nor"];
UIImage *login_dis_image = [UIImage imageNamed:@"loginBtn_Dis"];
UIImage *login_hig_image = [UIImage imageNamed:@"loginBtn_Nor"];
if (login_nor_image && login_dis_image && login_hig_image) {
config.logBtnImgs = @[login_nor_image, login_dis_image, login_hig_image];
}
config.logBtnTextColor = [UIColor whiteColor];
config.logBtnFont = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*15 weight:UIFontWeightMedium];
CGFloat loginButtonWidth = [UIScreen mainScreen].bounds.size.width/375*315;
CGFloat loginButtonHeight = [UIScreen mainScreen].bounds.size.width/375*43;
JVLayoutConstraint *loginConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
JVLayoutConstraint *loginConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterY multiplier:1 constant:5];
JVLayoutConstraint *loginConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:loginButtonWidth];
JVLayoutConstraint *loginConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:loginButtonHeight];
config.logBtnConstraints = @[loginConstraintX,loginConstraintY,loginConstraintW,loginConstraintH];
config.logBtnHorizontalConstraints = config.logBtnConstraints;
//勾選框
UIImage * uncheckedImg = [UIImage imageNamed:@"userAgreement_normal_icon"];
UIImage * checkedImg = [UIImage imageNamed:@"userAgreement_selected_icon"];
CGFloat checkViewWidth = [UIScreen mainScreen].bounds.size.width/375*12;
CGFloat checkViewHeight = [UIScreen mainScreen].bounds.size.width/375*12;
config.uncheckedImg = uncheckedImg;
config.checkedImg = checkedImg;
JVLayoutConstraint *checkViewConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeLeft multiplier:1 constant:[UIScreen mainScreen].bounds.size.width/375*30];
JVLayoutConstraint *checkViewConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemPrivacy attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
JVLayoutConstraint *checkViewConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:checkViewWidth];
JVLayoutConstraint *checkViewConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:checkViewHeight];
config.checkViewConstraints = @[checkViewConstraintX,checkViewConstraintY,checkViewConstraintW,checkViewConstraintH];
config.checkViewHorizontalConstraints = config.checkViewConstraints;
//隱私政策
CGFloat spacing = checkViewWidth + [UIScreen mainScreen].bounds.size.width/375*30 + 10;
config.privacyState = YES;
JVLayoutConstraint *privacyConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeLeft multiplier:1 constant:spacing];
JVLayoutConstraint *privacyConstraintX2 = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeRight multiplier:1 constant:-spacing+10];
JVLayoutConstraint *privacyConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeBottom multiplier:1 constant:-20]; // 距離屏幕bottom向上20
JVLayoutConstraint *privacyConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:50];
config.privacyConstraints = @[privacyConstraintX,privacyConstraintX2,privacyConstraintY,privacyConstraintH];
config.privacyHorizontalConstraints = config.privacyConstraints;
//loading
JVLayoutConstraint *loadingConstraintX = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
JVLayoutConstraint *loadingConstraintY = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemSuper attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
JVLayoutConstraint *loadingConstraintW = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeWidth multiplier:1 constant:30];
JVLayoutConstraint *loadingConstraintH = [JVLayoutConstraint constraintWithAttribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:JVLayoutItemNone attribute:NSLayoutAttributeHeight multiplier:1 constant:30];
config.loadingConstraints = @[loadingConstraintX,loadingConstraintY,loadingConstraintW,loadingConstraintH];
config.loadingHorizontalConstraints = config.loadingConstraints;
config.privacyTextFontSize = 12;
_config = config;
config.privacyTextAlignment = NSTextAlignmentCenter;
config.customPrivacyAlertViewBlock = ^(UIViewController *vc) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否同意用戶服務(wù)協(xié)議" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil]];
[vc presentViewController:alert animated:true completion:nil];
};
config.logoHidden = NO;
config.logBtnText = @"一鍵登錄認(rèn)證";
config.logBtnTextColor = [UIColor whiteColor];
config.numberColor = [UIColor blackColor];
config.appPrivacyOne = @[@"《用戶服務(wù)協(xié)議》", @"http://www.7500km.net/others/privacyPolicy"];
// config.appPrivacyTwo = @[@"應(yīng)用自定義服務(wù)條款2",@"https://www.jiguang.cn/about"];
config.privacyComponents = @[@"登錄即同意",@"和",@"、",@"并使用本機(jī)號(hào)碼登錄"];
config.appPrivacyColor = @[RGBA(142, 142, 142, 1), [UIColor blackColor]];
config.sloganTextColor = RGBA(142, 142, 142, 1);
config.navCustom = NO;
config.numberSize = 24;
// config.privacyState = YES;
/*
config.authPageBackgroundImage = [UIImage imageNamed:@"背景圖"];
config.navColor = [UIColor redColor];
config.preferredStatusBarStyle = 0;
config.navText = [[NSAttributedString alloc] initWithString:@"自定義標(biāo)題"];
config.navReturnImg = [UIImage imageNamed:@"自定義返回鍵"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 44, 44);
button.backgroundColor = [UIColor greenColor];
config.navControl = [[UIBarButtonItem alloc] initWithCustomView:button];
config.logoHidden = NO;
config.logBtnText = @"自定義登錄按鈕文字";
config.logBtnTextColor = [UIColor redColor];
config.numberColor = [UIColor blueColor];
config.appPrivacyOne = @[@"應(yīng)用自定義服務(wù)條款1",@"https://www.jiguang.cn/about"];
config.appPrivacyTwo = @[@"應(yīng)用自定義服務(wù)條款2",@"https://www.jiguang.cn/about"];
config.privacyComponents = @[@"文本1",@"文本2",@"文本3",@"文本4"];
config.appPrivacyColor = @[[UIColor redColor], [UIColor blueColor]];
config.sloganTextColor = [UIColor redColor];
config.navCustom = NO;
config.numberSize = 24;
config.privacyState = YES;
*/
__weak typeof(self)weakSelf = self;
[JVERIFICATIONService customUIWithConfig:config customViews:^(UIView *customAreaView) {
/// customAreaView 的frame是整個(gè)頁(yè)面的self.view.frame
/*
//添加一個(gè)自定義label
UILabel *lable = [[UILabel alloc] init];
lable.text = @"這是一個(gè)自定義label";
[lable sizeToFit];
lable.center = customAreaView.center;
[customAreaView addSubview:lable];
*/
UIEdgeInsets insets = UIEdgeInsetsMake(20, 0, 0, 0);
if (@available(iOS 11.0, *)) {
insets = [UIApplication sharedApplication].keyWindow.safeAreaInsets;
}
/// 自定義 textView
weakSelf.registerTextView = [[UITextView alloc] init];
weakSelf.registerTextView.text = @"還沒有賬號(hào)?我想要 注冊(cè) 一個(gè)賬號(hào)";
weakSelf.registerTextView.backgroundColor = [UIColor whiteColor];
weakSelf.registerTextView.textColor = RGBA(142, 142, 142, 1);
weakSelf.registerTextView.textAlignment = NSTextAlignmentRight;
weakSelf.registerTextView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
weakSelf.registerTextView.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*12 weight:UIFontWeightRegular];
weakSelf.registerTextView.showsVerticalScrollIndicator = NO;
weakSelf.registerTextView.scrollEnabled = NO;
weakSelf.registerTextView.editable = NO;
weakSelf.registerTextView.delegate = self;
weakSelf.registerTextView.center = customAreaView.center;
[customAreaView addSubview:weakSelf.registerTextView];
// [self.view addSubview:self.registerTextView];
[weakSelf.registerTextView makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(customAreaView);
make.bottom.mas_equalTo(customAreaView.mas_bottom).offset(-[UIScreen mainScreen].bounds.size.width/375*60 - insets.bottom);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*210);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*14);
}];
[self agreementSetupHanleTextView:self.registerTextView];
weakSelf.loginTextView = [[UITextView alloc] init];
weakSelf.loginTextView.text = @"不是此賬號(hào)?用其他賬號(hào) 登錄 ";
weakSelf.loginTextView.backgroundColor = [UIColor whiteColor];
weakSelf.loginTextView.textColor = RGBA(142, 142, 142, 1);
weakSelf.loginTextView.textAlignment = NSTextAlignmentRight;
weakSelf.loginTextView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
weakSelf.loginTextView.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*12 weight:UIFontWeightRegular];
weakSelf.loginTextView.showsVerticalScrollIndicator = NO;
weakSelf.loginTextView.scrollEnabled = NO;
weakSelf.loginTextView.editable = NO;
weakSelf.loginTextView.delegate = self;
weakSelf.loginTextView.center = customAreaView.center;
[customAreaView addSubview:weakSelf.loginTextView];
// [self.view addSubview:self.loginTextView];
[weakSelf.loginTextView makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(customAreaView);
make.bottom.mas_equalTo(weakSelf.registerTextView.mas_top).offset(-[UIScreen mainScreen].bounds.size.width/375*10);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*180);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*14);
}];
[self agreementSetupHanleTextView:self.loginTextView];
}];
[self clickQuickLogin];
}
- (void)clickQuickLogin {
// SDK 請(qǐng)求授權(quán)一鍵登錄
[JVERIFICATIONService getAuthorizationWithController:self hide:NO animated:YES timeout:5*1000 completion:^(NSDictionary *result) {
NSLog(@"一鍵登錄 result:%@", result);
// result 字典 獲取到token時(shí)key有operator、code、loginToken字段,獲取不到token時(shí)key為code和content字段
// [JVERIFICATIONService dismissLoginControllerAnimated:YES completion:nil]; // 認(rèn)證頁(yè)面 dismiss
NSInteger code = [[NSString stringWithFormat:@"%@", result[@"code"]] integerValue];
if (code == 6000) {
NSLog(@"獲取loginToken成功");
NSString *loginToken = [NSString stringWithFormat:@"%@", result[@"loginToken"]];
if (![loginToken isEqualToString:@"(null)"] && loginToken.length > 0) {
[self gainLoginRequestLoginToken:loginToken];
} else {
NSLog(@"返回loginToken錯(cuò)誤。。。。");
[JVERIFICATIONService dismissLoginControllerAnimated:NO completion:nil]; // 認(rèn)證頁(yè)面 dismiss
}
} else if (code == 6001) {
NSLog(@"獲取loginToken失敗");
[self setupUINormalView];
[KAlertViewFactory showToastWithMessage:@"一鍵登錄失敗,請(qǐng)去賬號(hào)密碼登錄"];
[JVERIFICATIONService dismissLoginControllerAnimated:NO completion:nil]; // 認(rèn)證頁(yè)面 dismiss
} else if (code == 6006) {
NSLog(@"預(yù)取號(hào)信息過期,請(qǐng)重新預(yù)取號(hào)");
[self setupUINormalView];
[JVERIFICATIONService clearPreLoginCache]; // 清除預(yù)取號(hào)緩存
[KAlertViewFactory showToastWithMessage:@"一鍵登錄失敗,請(qǐng)去賬號(hào)密碼登錄"];
[JVERIFICATIONService dismissLoginControllerAnimated:NO completion:nil]; // 認(rèn)證頁(yè)面 dismiss
}
else if (code == 4033) {
/// 需用戶再次檢查極光開發(fā)者后臺(tái)一鍵登錄相關(guān)的所有配置是否完善且通過審核,如都正常請(qǐng)將app卸載重裝,清空在配置生效先調(diào)用接口報(bào)錯(cuò)的緩存。
// [KAlertViewFactory showToastWithMessage:@"不是一鍵登錄用戶"];
[self setupUINormalView];
[KAlertViewFactory showToastWithMessage:@"一鍵登錄失敗,請(qǐng)去賬號(hào)密碼登錄"];
[JVERIFICATIONService dismissLoginControllerAnimated:NO completion:nil]; // 認(rèn)證頁(yè)面 dismiss
} else {
[self setupUINormalView];
[KAlertViewFactory showToastWithMessage:@"一鍵登錄失敗,請(qǐng)去賬號(hào)密碼登錄"];
[JVERIFICATIONService dismissLoginControllerAnimated:NO completion:nil]; // 認(rèn)證頁(yè)面 dismiss
}
} actionBlock:^(NSInteger type, NSString *content) {
NSLog(@"一鍵登錄 actionBlock :%ld %@", (long)type , content);
}];
}
- (void)agreementSetupHanleTextView:(UITextView *)textView {
if (textView == self.agreementTextView) {
NSString *agreementMessage = self.agreementTextView.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementMessage];
[attributedString addAttribute:NSLinkAttributeName
value:@"2"
range:[[attributedString string] rangeOfString:@"《用戶服務(wù)協(xié)議》"]];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*11] range:[[attributedString string] rangeOfString:agreementMessage]];
[attributedString addAttribute:NSForegroundColorAttributeName value:RGBA(142, 142, 142, 1) range:[[attributedString string] rangeOfString:agreementMessage]];
self.agreementTextView.linkTextAttributes = @{ NSForegroundColorAttributeName: [UIColor colorWithRed:5.0/255.0 green:5.0/255.0 blue:5.0/255.0 alpha:1],
NSUnderlineColorAttributeName: [UIColor clearColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)};
self.agreementTextView.attributedText = attributedString;
} else if (textView == self.registerTextView) {
NSString *agreementMessage = self.registerTextView.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementMessage];
[attributedString addAttribute:NSLinkAttributeName
value:@"register2"
range:[[attributedString string] rangeOfString:@"注冊(cè)"]];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*11] range:[[attributedString string] rangeOfString:agreementMessage]];
[attributedString addAttribute:NSForegroundColorAttributeName value:RGBA(142, 142, 142, 1) range:[[attributedString string] rangeOfString:agreementMessage]];
self.registerTextView.linkTextAttributes = @{ NSForegroundColorAttributeName: RGBA(245, 40, 40, 1),
NSUnderlineColorAttributeName: [UIColor clearColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)};
self.registerTextView.attributedText = attributedString;
} else if (textView == self.loginTextView) {
NSString *agreementMessage = self.loginTextView.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:agreementMessage];
[attributedString addAttribute:NSLinkAttributeName
value:@"login2"
range:[[attributedString string] rangeOfString:@"登錄"]];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*11] range:[[attributedString string] rangeOfString:agreementMessage]];
[attributedString addAttribute:NSForegroundColorAttributeName value:RGBA(142, 142, 142, 1) range:[[attributedString string] rangeOfString:agreementMessage]];
self.loginTextView.linkTextAttributes = @{ NSForegroundColorAttributeName: RGBA(245, 40, 40, 1),
NSUnderlineColorAttributeName: [UIColor clearColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)};
self.loginTextView.attributedText = attributedString;
}
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction {
[JVERIFICATIONService dismissLoginControllerAnimated:YES completion:nil]; // 認(rèn)證頁(yè)面 dismiss
if ([URL.absoluteString isEqualToString:@"2"]) {
CheckUserAgreementCTRL *agreementVC = [[CheckUserAgreementCTRL alloc] init];
agreementVC.originMark = 2;
[self.navigationController pushViewController:agreementVC animated:YES];
} else if ([URL.absoluteString isEqualToString:@"register2"]) {
NSLog(@"點(diǎn)擊注冊(cè)");
// RegisterViewCTRL *registerVC = [[RegisterViewCTRL alloc] init];
// registerVC.title = @"注冊(cè)";
// [self.navigationController pushViewController:registerVC animated:YES];
[self registerPage];
[JVERIFICATIONService dismissLoginControllerAnimated:NO completion:nil]; // 退出認(rèn)證頁(yè)面 dismiss
} else if ([URL.absoluteString isEqualToString:@"login2"]) {
NSLog(@"點(diǎn)擊登錄");
// PasswordLoginCTRL *loginVC = [[PasswordLoginCTRL alloc] init];
// [self.navigationController pushViewController:loginVC animated:YES];
[JVERIFICATIONService dismissLoginControllerAnimated:YES completion:nil]; // 退出認(rèn)證頁(yè)面 dismiss
}
return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
// 禁用文本復(fù)制、粘貼
return NO;
}
- (void)registerPage {
RegisterViewCTRL *registerVC = [[RegisterViewCTRL alloc] init];
registerVC.title = @"注冊(cè)";
NSArray *VCArrs = self.navigationController.viewControllers; // 當(dāng)前VC所在的VC數(shù)組
if (VCArrs.count > 0 && VCArrs.lastObject == self) { // 數(shù)組最后一個(gè)是當(dāng)前的VC
__weak typeof(self) weakSelf = self;
void (^completion)(void) = ^{
NSMutableArray *VCMutableArrs = [weakSelf.navigationController.viewControllers mutableCopy];
// 最后([下一頁(yè)面 VC])
if (VCMutableArrs.count > 0 && [VCMutableArrs.lastObject isKindOfClass:[registerVC class]]) {
[VCMutableArrs removeObjectAtIndex:VCMutableArrs.count - 2];
weakSelf.navigationController.viewControllers = [VCMutableArrs copy];
}
};
// 設(shè)置block
[CATransaction setCompletionBlock:completion]; // 承接上邊的block
[CATransaction begin];
[self.navigationController pushViewController:registerVC animated:YES];
// 提交
[CATransaction commit];
}
}
#pragma mark -- 一鍵登錄時(shí),自動(dòng)注冊(cè)
- (void)gainLoginRequestLoginToken:(NSString *)loginToken {
NSDictionary *params = @{
@"loginToken":loginToken
};
__weak typeof(self) weakSelf = self;
[[WL_AFShareManager sharedManager] POST:[WL_AFShareManager LFT_UrlString:@"后臺(tái)服務(wù)器接口,將loginToken傳到后臺(tái)服務(wù)器/one_click_login"] parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"%@", task.currentRequest.URL);
NSInteger reCode = [[responseObject objectForKey:@"reCode"] integerValue];
if (reCode == 200) {
NSString *dataStr = [responseObject objectForKey:@"data"];
[KAlertViewFactory showToastWithMessage:dataStr];
// AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
// _quickLoginView = [[QuickLoginSucceedView alloc] initWithFrame:appDelegate.window.frame];
//
// [appDelegate.window addSubview:_quickLoginView];
// _quickLoginView.quickLoginSucceedBlock = ^(BOOL isLoginSucceed) {
// if (isLoginSucceed) {
// [weakSelf.navigationController popViewControllerAnimated:YES];
// }
// };
[JVERIFICATIONService dismissLoginControllerAnimated:YES completion:nil]; // 認(rèn)證頁(yè)面 dismiss
} else {
NSString *message = [responseObject valueForKey:@"reMessage"];
[KAlertViewFactory showToastWithMessage:message];
[JVERIFICATIONService dismissLoginControllerAnimated:YES completion:nil]; // 認(rèn)證頁(yè)面 dismiss
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@", task.currentRequest.URL);
NSLog(@"error --->>> %@", error);
[JVERIFICATIONService dismissLoginControllerAnimated:YES completion:nil]; // 認(rèn)證頁(yè)面 dismiss
}];
}
#pragma mark -- 賬號(hào)登錄
- (void)loginAccount {
// 賬號(hào)登錄
NSDictionary *params = @{
@"country_code":@"+86",
@"mobile":[NSString stringWithFormat:@"%@", self.phoneTextField.text],
@"password":[NSString stringWithFormat:@"%@", self.passwordTextField.text]
};
[SVProgressHUD showWithStatus:@"正在加載"];
// [SVProgressHUD dismiss];
[[WL_AFShareManager sharedManager] POST:[WL_AFShareManager LFT_UrlString:@"登錄接口/login"] parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"%@",task.currentRequest.URL);
NSInteger reCode = [[responseObject valueForKey:@"reCode"] integerValue];
if (reCode == 200) {
responseObject = [WL_Tool Handle7500kmresponseObject:responseObject];
NSDictionary *data = [responseObject objectForKey:@"data"] ;
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"user_id"]] forKey:@"user_id"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"sex"]] forKey:@"sex"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"user_uuid"]] forKey:@"user_uuid"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"nick_name"]] forKey:@"nick_name"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"head_img_address"]] forKey:@"head_img_address"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"member_type"]] forKey:@"member_type"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"member_expire_time"]] forKey:@"member_expire_time"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"reader_member_type"]] forKey:@"reader_member_type"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"reader_member_expire_time"]] forKey:@"reader_member_expire_time"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"russian_beans"]] forKey:@"russian_beans"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"status"]] forKey:@"status"];
[user setObject:[NSString stringWithFormat:@"%@", [data objectForKey:@"token"]] forKey:@"token"];
[user synchronize];
if (self.loginVieCTRLBlock != nil)
{
[[WL_Tool getInstance] GainUserInfo:self];
self.loginVieCTRLBlock();
[self.navigationController popViewControllerAnimated:YES];
}
} else {
NSString *message = [responseObject valueForKey:@"reMessage"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alert show];
}
[SVProgressHUD dismiss];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@",task.currentRequest.URL);
NSLog(@"error-->%@",error);
[SVProgressHUD dismiss];
}];
}
@end