123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- //
- // AppDelegate+XYShanYan.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2019/12/11.
- // Copyright © 2019 翟玉磊. All rights reserved.
- //
- #import "AppDelegate+XYShanYan.h"
- #import <CL_ShanYanSDK/CL_ShanYanSDK.h>
- #import "XYOtherLoginView.h"
- #import "XYLoginViewController.h"
- #import "XYSetupUserInfoViewController.h"
- #import <Bugly/Bugly.h>
- #import <CloudPushSDK/CloudPushSDK.h>
- #import "XYHeadlineRoomManage.h"
- #import "YQAnmationResourceMag.h"
- @implementation AppDelegate (XYShanYan)
- /*
- 创蓝闪验初始化
- */
- - (void)cl_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-
- // 非登录状态进行初始化
- NSString *appId = self.appConfigModel.channelConfig.oneKeyLogin.appId;
- [CLShanYanSDKManager initWithAppId:appId complete:^(CLCompleteResult * _Nonnull completeResult) {
- if (completeResult.error) {
- NSLog(@"闪验SDK 初始化失败:%@",completeResult.message);
- }else{
- NSLog(@"闪验SDK 初始化成功:%@",completeResult.message);
- }
- }];
- [CLShanYanSDKManager printConsoleEnable:NO];
- }
- /// 创建快捷登录页(一键登录)
- - (void)createQulickLoginPageVC {
- // 防止出现presentView
- // [self dismissViewController:^{
- //
- // }];
-
- if ([XYUserInfoManager nowUser]) {
- [self logoutHandleSuccess:^(BOOL success) {
- [self createQulickLoginPageVCLoading];
- }];
- }else {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self createQulickLoginPageVCLoading];
- });
- }
- }
- - (void)createQulickLoginPageVCLoading {
- ///防止多次登录
- if (!self.tabbarVC) {
- return;
- }
- if (self.isLogin) {
- return;
- }
-
- NSString *appId = self.appConfigModel.channelConfig.oneKeyLogin.appId;
- if (StringIsEmpty(appId)) {
- // 跳转到其他登录界面
- [self createLoginPageVC];
- return;
- }
- // 获取预取号 在调取登录页之前调用
- [SVProgressHUD showWithStatus:@"加载中..."];
- [CLShanYanSDKManager preGetPhonenumber:^(CLCompleteResult * _Nonnull completeResult) {
- dispatch_async(dispatch_get_main_queue(), ^{
- // 隐藏loading操作
- [SVProgressHUD dismiss];
- });
- if (completeResult.error) {
- NSLog(@"%@f",completeResult.error.description);
- // 获取失败则说明不支持一键登录
- // 跳转到其他登录界面
- [self createLoginPageVC];
- }else{
- NSLog(@"%@",completeResult.yy_modelDescription);
- // 不建议调用后立即调用拉起授权页方法(此方法是异步)这里增加两秒的延迟
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // 获取成功则拉取一键登录登录页
- if ([XYUserInfoManager nowUser]) {
- [self logoutHandleSuccess:^(BOOL success) {
- [self qulickLogin];
- }];
- }else {
- [self qulickLogin];
- }
- });
- }
- }];
- }
- /// 创建其他登录方式页 (第三方和手机验证码登录)
- - (void)createLoginPageVC {
- dispatch_async(dispatch_get_main_queue(), ^{
- XYLoginViewController *loginVC = [XYLoginViewController new];
- BaseNavigationController *loginNav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
- [[ApplicationDelegate getCurrentController] presentViewController:loginNav animated:NO completion:nil];
- });
- }
- /// 拉取一键登录授权页面
- - (void)qulickLogin {
-
- CLUIConfigure * baseUIConfigure = [self configureInitUI];
-
- [CLShanYanSDKManager quickAuthLoginWithConfigure:baseUIConfigure openLoginAuthListener:^(CLCompleteResult * _Nonnull completeResult) {
- dispatch_async(dispatch_get_main_queue(), ^{
- // 隐藏loading操作
- [SVProgressHUD dismiss];
- });
- if (completeResult.error) {
- NSLog(@"授权页拉起失败 error:%@",completeResult.error.description);
- //关闭授权页
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- // 跳转到其他登录界面
- self.isLogin = NO;
- [self createLoginPageVC];
- }];
- }else{
- NSLog(@"授权页拉起成功");
- self.isLogin = YES;
- }
- } oneKeyLoginListener:^(CLCompleteResult * _Nonnull completeResult) {
- dispatch_async(dispatch_get_main_queue(), ^{
- // 隐藏loading操作
- [SVProgressHUD dismiss];
- });
- if (completeResult.error) {
- NSLog(@"一键登录失败 error:%@",completeResult.error.description);
- //提示:错误无需提示给用户,可以在用户无感知的状态下直接切换登录方式
- if (completeResult.code == 1011){
- //用户取消登录(点返回)
- //处理建议:如无特殊需求可不做处理,仅作为交互状态回调,此时已经回到当前用户自己的页面
- //点击sdk自带的返回,无论是否设置手动销毁,授权页面都会强制关闭
- } else{
- //处理建议:其他错误代码表示闪验通道无法继续,可以统一走开发者自己的其他登录方式,也可以对不同的错误单独处理
- //1003 一键登录获取token失败
- //其他 其他错误//
-
- }
- //关闭授权页
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- // 跳转到其他登录界面
- self.isLogin = NO;
- [self createLoginPageVC];
- }];
- }else{
- kWEAKSELF
- NSLog(@"一键登录获取token成功");
- NSString *token = completeResult.data[@"token"];
- // 验证token
- [[XYUserAPIManager new] byOneKeyWithCert:token inviteCode:@"" successHandler:^(ZYLResponseModel *responseModel) {
-
- BOOL isCoolPeriod = [[AppDelegate sharedDelegate] isCoolPeriod:responseModel.data];
- [AppDelegate sharedDelegate].XYCoolPeriodAgainLogin = ^(BOOL success) {
- [weakSelf parseQuickLoginResponseModel:responseModel];
- };
- if (isCoolPeriod) {
- return;
- }
- [weakSelf parseQuickLoginResponseModel:responseModel];
-
- } failureHandler:^(NSError *error) {
- [SVProgressHUD dismiss];
- //关闭授权页
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- // 跳转到其他登录界面
- self.isLogin = NO;
- [self createLoginPageVC];
- }];
- }];
- }
- }];
- }
- - (void)parseQuickLoginResponseModel:(ZYLResponseModel *)responseModel{
- if (responseModel.codeState) {
- NSString *refreshToken = responseModel.data[@"refreshToken"];
- // 判断是否绑定手机号
- if (StringIsEmpty(refreshToken)) {
- BOOL needProfile = [responseModel.data[@"needProfile"] boolValue];
- // 是否是新用户
- if (needProfile) {
- // 新用户则跳转到设置信息界面
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:XYSetupUserInfoViewController.new];
- [[ApplicationDelegate getCurrentController] presentViewController:nav animated:NO completion:nil];
- }];
- }else {
- [self loginHandleSuccess:^(BOOL success) {
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- }];
- }];
- }
- }else {
- // 不为空说明未绑定手机号 跳转到绑定手机号逻辑
- //关闭授权页
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- // 跳转到其他登录界面
- XYLoginViewController *loginVC = [XYLoginViewController new];
- loginVC.sendCodeType = XY_Phone_Verification_Code_type_Binding;
- loginVC.refreshToken = refreshToken;
- BaseNavigationController *loginNav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
- [[ApplicationDelegate getCurrentController] presentViewController:loginNav animated:NO completion:nil];
- }];
- }
- }else {
- [SVProgressHUD showInfoWithStatus:responseModel.message];
- }
-
- }
- /// 创建一键登录的UI配置文件
- - (CLUIConfigure *)configureInitUI {
- CLUIConfigure * baseUIConfigure = [CLUIConfigure new];
-
- UIViewController *currentVC = [self getCurrentController];
- UIView *currentView = currentVC.view;
- // currentVC 为拉起授权页时的当前页面控制器
- baseUIConfigure.viewController = currentVC;
-
- // 导航条
- baseUIConfigure.clNavigationBackgroundClear = @(YES);
- baseUIConfigure.clNavigationBottomLineHidden = @(YES);
- baseUIConfigure.clNavigationAttributesTitleText = [[NSAttributedString alloc] initWithString:kLocalizedString(@"登录/注册") attributes:@{NSFontAttributeName:Font_B(20)}];
- baseUIConfigure.clNavigationTintColor = Color_TextFont;
- baseUIConfigure.clNavigationBarTintColor = Color_White;
-
- // 返回按钮
- baseUIConfigure.clNavigationLeftControl = [UIBarButtonItem customItemWithTitle:@"" titleColor:Color_TextFont imageName:@"icon_back" target:self selector:@selector(loginCancelAction:) contentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
- baseUIConfigure.clNavigationBackBtnHidden = @(YES);
-
- // logo
- baseUIConfigure.clLogoImage = ImageNamed(@"icon_logo_114");
- baseUIConfigure.clLogoCornerRadius = @(2.0f);
-
- //运营商品牌标签
- baseUIConfigure.clSloganTextColor = Color_TextGray;
- baseUIConfigure.clSloganTextFont = Font(12);
- baseUIConfigure.clSlogaTextAlignment = @(NSTextAlignmentCenter);
-
- // 手机号显示控件
- baseUIConfigure.clPhoneNumberColor = Color_TextFont;
- baseUIConfigure.clPhoneNumberFont = Font_B(24);
- baseUIConfigure.clPhoneNumberTextAlignment = @(NSTextAlignmentCenter);
-
- // 一键登录按钮 控件
- baseUIConfigure.clLoginBtnText = kLocalizedString(@"一键登录");
- baseUIConfigure.clLoginBtnTextColor = Color_White;
- baseUIConfigure.clLoginBtnTextFont = Font_B(18);
- baseUIConfigure.clLoginBtnNormalBgImage = [UIImage gradientColorImageFromColors:@[ColorFromHexString(@"#5D26FF"), ColorFromHexString(@"#9059FF")] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(SCREEN_WIDTH - 80.0f, 48.0f)];
- baseUIConfigure.clLoginBtnCornerRadius = @(8.0f);
-
- // 协议条款
- baseUIConfigure.clAppPrivacyColor = @[Color_TextGray, Color_Blue];
- baseUIConfigure.clAppPrivacyTextFont = Font(12);
- baseUIConfigure.clAppPrivacyTextAlignment = @(NSTextAlignmentLeft);
- baseUIConfigure.clAppPrivacyFirst = @[kLocalizedString(@"《用户协议》"),[NSURL URLWithString:App_User_Url]];
- baseUIConfigure.clAppPrivacySecond = @[kLocalizedString(@"《隐私协议》"),[NSURL URLWithString:App_Privacy_Url]];
- baseUIConfigure.clAppPrivacyNormalDesTextFirst = kLocalizedString(@"登录即代表您已同意");
- baseUIConfigure.clAppPrivacyPunctuationMarks = @(YES);
- baseUIConfigure.clAppPrivacyNormalDesTextSecond = @"";
- baseUIConfigure.clAppPrivacyNormalDesTextThird = @"";
- baseUIConfigure.clAppPrivacyNormalDesTextFourth = @"";
- baseUIConfigure.clAppPrivacyNormalDesTextLast = @"";
-
- // 闪验SLOGAN
- baseUIConfigure.clShanYanSloganHidden = @(YES);
-
- // 协议页
- baseUIConfigure.clAppPrivacyWebBackBtnImage = [UIImage imageNamed:@"title_back"];
-
- //CheckBox
- baseUIConfigure.clCheckBoxHidden = @(NO);
- baseUIConfigure.clCheckBoxValue = @(NO);
- baseUIConfigure.clCheckBoxSize = [NSValue valueWithCGSize:CGSizeMake(30.0f, 30.0f)];
- baseUIConfigure.clCheckBoxImageEdgeInsets = [NSValue valueWithUIEdgeInsets:UIEdgeInsetsMake(2, 2, 2, 2)];
- baseUIConfigure.clCheckBoxVerticalAlignmentToAppPrivacyTop = @(YES);
- // baseUIConfigure.clCheckBoxVerticalAlignmentToAppPrivacyCenterY = @(YES);
- baseUIConfigure.clCheckBoxCheckedImage = [UIImage imageNamed:@"login_sure"];
- baseUIConfigure.clCheckBoxUncheckedImage = [UIImage imageNamed:@"login_unsure"];
-
- // 控件布局设置
- CGFloat screenWidth_Portrait;
- CGFloat screenHeight_Portrait;
- CGFloat screenWidth_Landscape;
- CGFloat screenHeight_Landscape;
- UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
- if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
- screenWidth_Portrait = UIScreen.mainScreen.bounds.size.width;
- screenHeight_Portrait = UIScreen.mainScreen.bounds.size.height;
- screenWidth_Landscape = UIScreen.mainScreen.bounds.size.height;
- screenHeight_Landscape = UIScreen.mainScreen.bounds.size.width;
- }else{
- screenWidth_Portrait = UIScreen.mainScreen.bounds.size.height;
- screenHeight_Portrait = UIScreen.mainScreen.bounds.size.width;
- screenWidth_Landscape = UIScreen.mainScreen.bounds.size.width;
- screenHeight_Landscape = UIScreen.mainScreen.bounds.size.height;
- }
-
- //layout 布局
- //布局-竖屏
- CLOrientationLayOut * clOrientationLayOutPortrait = [CLOrientationLayOut new];
-
- //一键登录按钮居中
- clOrientationLayOutPortrait.clLayoutLoginBtnCenterY = @(0);
- clOrientationLayOutPortrait.clLayoutLoginBtnHeight = @(48.0f);
- clOrientationLayOutPortrait.clLayoutLoginBtnLeft = @(40.0f);
- clOrientationLayOutPortrait.clLayoutLoginBtnRight = @(-40.0f);
-
- clOrientationLayOutPortrait.clLayoutPhoneCenterY = @(clOrientationLayOutPortrait.clLayoutLoginBtnCenterY.floatValue-20.0f-clOrientationLayOutPortrait.clLayoutLoginBtnHeight.floatValue);
- clOrientationLayOutPortrait.clLayoutPhoneLeft = @(40.0f);
- clOrientationLayOutPortrait.clLayoutPhoneRight = @(-40.0f);
- clOrientationLayOutPortrait.clLayoutPhoneHeight = @(33.0f);
-
- clOrientationLayOutPortrait.clLayoutLogoWidth = @(80.0f);
- clOrientationLayOutPortrait.clLayoutLogoHeight = @(80.0f);
- clOrientationLayOutPortrait.clLayoutLogoCenterX = @(0);
- clOrientationLayOutPortrait.clLayoutLogoTop = @(40.0f+NAVGATION_HEIGHT);
-
- clOrientationLayOutPortrait.clLayoutSloganLeft = @(40.0f);
- clOrientationLayOutPortrait.clLayoutSloganRight = @(-40.0f);
- clOrientationLayOutPortrait.clLayoutSloganHeight = @(17.0f);
- clOrientationLayOutPortrait.clLayoutSloganTop = @(clOrientationLayOutPortrait.clLayoutLogoTop.floatValue+clOrientationLayOutPortrait.clLayoutLogoHeight.floatValue+10.0f);
-
- clOrientationLayOutPortrait.clLayoutAppPrivacyLeft = @(60.0f);
- clOrientationLayOutPortrait.clLayoutAppPrivacyRight = @(-40.0f);
- clOrientationLayOutPortrait.clLayoutAppPrivacyBottom = @(-(20.0f+HOME_INDICATOR_HEIGHT));
-
-
- //自定义控件 其他登录
- __weak typeof(self) weakSelf = self;
- baseUIConfigure.customAreaView = ^(UIView * _Nonnull customAreaView) {
- __strong typeof(weakSelf) strongSelf = weakSelf;
-
- /// 第三方数组
- NSMutableArray *otherLoginItemArray = [NSMutableArray new];
-
- ///是否安装微信
- if ([XYSocialRegisterHandler isWXAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_WX_Login])) {
- [otherLoginItemArray addObject:Wechat_icon];
- }
- ///是否安装QQ
- if ([XYSocialRegisterHandler isQQAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_QQ_Login])) {
- [otherLoginItemArray addObject:QQ_icon];
- }
- // 是否安装微博
- if ([XYSocialRegisterHandler isSinaAppInstalled] && StringIsNotEmpty([XYAppConfigOauthsModel getOauthsModelWithType:XY_Login_type_Sina_Login])) {
- [otherLoginItemArray addObject:Sina_icon];
- }
-
- [otherLoginItemArray addObject:Phone_icon];
-
- XYOtherLoginView *otherLoginView = [[XYOtherLoginView alloc] initWithFrame:CGRectMake(40.0f, SCREEN_HEIGHT/2 + 24.0f + 40.0f, SCREEN_WIDTH-40.0f*2, 113.0f)];
- [otherLoginView setupLoginTypeDataWithArray:otherLoginItemArray selectCallback:^(NSInteger index) {
- /// 0微信 1QQ 2微博 3手机验证码
- NSString *itemName = otherLoginItemArray[index];
- if ([itemName isEqualToString:Wechat_icon]) {
- [strongSelf wxLoginActionWithLoginType:XY_Login_type_Quick_Login];
- }else if ([itemName isEqualToString:Sina_icon]) {
- [strongSelf sinaLoginActionWithLoginType:XY_Login_type_Quick_Login];
- }else if ([itemName isEqualToString:QQ_icon]) {
- [strongSelf QQLoginActionWithLoginType:XY_Login_type_Quick_Login];
- }else if ([itemName isEqualToString:Phone_icon]) {
- [strongSelf phoneCodeLoginActionWithLoginType:XY_Login_type_Quick_Login];
- }
- }];
- [customAreaView addSubview:otherLoginView];
- };
-
- baseUIConfigure.clOrientationLayOutPortrait = clOrientationLayOutPortrait;
-
- return baseUIConfigure;
- }
- #pragma mark — LoginAction
- /// 取消登录
- - (void)loginCancelAction:(id)sender {
- NSLog(@"取消登录了");
- // 用户取消登录(授权页点击返回) 【处理建议:若无特殊需求可不做处理】
- // 关闭授权页
- self.isLogin = NO;
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:nil];
- }
- /// 微信登录
- - (void)wxLoginActionWithLoginType:(XY_Login_type)loginType {
- NSLog(@"微信登录");
- [[XYSocialRegisterHandler sharedInstance] wechatLogin:@"snsapi_userinfo" state:@"123" completion:^(BOOL success, id _Nonnull info) {
- if (success) {
- NSLog(@"微信授权成功code:%@", info)
- ///判断是否在闪验的授权页
- if (loginType == XY_Login_type_Quick_Login) {
- /// 在快捷登录界面(一键登录)
- [self byThirdPartyOAuthWithLoginType:XY_Login_type_WX_Login code:info];
- }else {
- /// 在其他登录界面 发送通知回调
- [NotificationCenter postNotificationName:WECHAT_LOGIN_SUCCESS_NOTIFICATION object:@{@"code":info}];
- }
- }
- }];
- }
- /// qq登录
- - (void)QQLoginActionWithLoginType:(XY_Login_type)loginType {
- NSLog(@"QQ登录");
- [[XYSocialRegisterHandler sharedInstance] qqLoginCompletion:^(BOOL success, id _Nonnull info) {
- if (success) {
- NSLog(@"qq授权成功code:%@", info);
- ///判断是否在闪验的授权页
- if (loginType == XY_Login_type_Quick_Login) {
- /// 在快捷登录界面(一键登录)
- [self byThirdPartyOAuthWithLoginType:XY_Login_type_QQ_Login code:info];
- }else {
- /// 在其他登录界面 发送通知回调
- [NotificationCenter postNotificationName:QQ_LOGIN_SUCCESS_NOTIFICATION object:@{@"code":info}];
- }
- }
- }];
- }
- /// 新浪微博登录
- - (void)sinaLoginActionWithLoginType:(XY_Login_type)loginType {
- NSLog(@"微博登录");
- [[XYSocialRegisterHandler sharedInstance] sinaLoginCompletion:^(BOOL success, id _Nonnull info) {
- if (success) {
- NSLog(@"qq授权成功code:%@", info);
- ///判断是否在闪验的授权页
- if (loginType == XY_Login_type_Quick_Login) {
- /// 在快捷登录界面(一键登录)
- [self byThirdPartyOAuthWithLoginType:XY_Login_type_Sina_Login code:info];
- }else {
- /// 在其他登录界面 发送通知回调
- [NotificationCenter postNotificationName:SINA_LOGIN_SUCCESS_NOTIFICATION object:@{@"code":info}];
- }
- }
- }];
- }
- /// 手机号验证码登录
- - (void)phoneCodeLoginActionWithLoginType:(XY_Login_type)loginType {
- NSLog(@"验证码登录");
- //关闭授权页
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- // 跳转到其他登录界面
- [self createLoginPageVC];
- }];
- }
- - (void)byThirdPartyOAuthWithLoginType:(XY_Login_type)loginType code:(NSString *)code {
- kWEAKSELF
- [[XYUserAPIManager new] byThirdPartyOAuthWithType:loginType code:code inviteCode:@"" successHandler:^(ZYLResponseModel *responseModel) {
-
- BOOL isCoolPeriod = [[AppDelegate sharedDelegate] isCoolPeriod:responseModel.data];
- [AppDelegate sharedDelegate].XYCoolPeriodAgainLogin = ^(BOOL success) {
- [weakSelf parseThirdLoginResponseModel:responseModel];
- };
- if (isCoolPeriod) {
- return;
- }
- [weakSelf parseThirdLoginResponseModel:responseModel];
- } failureHandler:^(NSError *error) {
- [SVProgressHUD showInfoWithStatus:error.domain];
- }];
- }
- - (void)parseThirdLoginResponseModel:(ZYLResponseModel *)responseModel{
- kWEAKSELF
- if (responseModel.codeState) {
- NSString *refreshToken = responseModel.data[@"refreshToken"];
- // 判断是否绑定手机号
- if (StringIsEmpty(refreshToken)) {
- BOOL needProfile = [responseModel.data[@"needProfile"] boolValue];
- // 是否是新用户
- if (needProfile) {
- // 新用户则跳转到设置信息界面
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:XYSetupUserInfoViewController.new];
- [[ApplicationDelegate getCurrentController] presentViewController:nav animated:NO completion:nil];
- }];
- }else {
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- [weakSelf loginHandleSuccess:nil];
- }];
- }
- }else {
- // 不为空说明未绑定手机号 跳转到绑定手机号逻辑
- //关闭授权页
- [CLShanYanSDKManager finishAuthControllerAnimated:YES Completion:^{
- // 跳转到其他登录界面
- XYLoginViewController *loginVC = [XYLoginViewController new];
- loginVC.sendCodeType = XY_Phone_Verification_Code_type_Binding;
- loginVC.refreshToken = refreshToken;
- BaseNavigationController *loginNav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
- [[ApplicationDelegate getCurrentController] presentViewController:loginNav animated:NO completion:nil];
- }];
- }
- }else {
- [SVProgressHUD showInfoWithStatus:responseModel.message];
- }
-
- }
- /// 登录成功后,先获取详细个人信息,然后登录第三方
- - (void)loginHandleSuccess:(void(^ _Nullable)(BOOL success))block {
-
- // 1.获取详细个人信息
- [[XYUserInfoManager sharedInstance] updataUserInfoSuccess:^(BOOL isSuccess) {
- NSLog(@"1.获取详细个人信息返回");
- [Bugly setUserIdentifier:[XYUserInfoManager nowUser].userNo];//Bugly用户标示
-
- // 2.获取数据登录第三方
- [self loginReqeustData:^(BOOL success) {
- NSLog(@"2.获取数据登录第三方返回");
- // 3.发送登录通知
- [NotificationCenter postNotificationName:USER_LOGIN_STATUS_NOTIFICATION object:nil];
- //登录成功获取通知权限
- UIApplication *ap = [UIApplication sharedApplication];
- [self registerAPNS:ap];
- !block?:block(YES);
- }];
- }];
- }
- - (void)loginReqeustData:(void(^)(BOOL success))block {
- dispatch_group_t group = dispatch_group_create();
- dispatch_queue_t queue = dispatch_queue_create("login.data", DISPATCH_QUEUE_SERIAL);
-
- dispatch_group_enter(group);
- dispatch_async(queue, ^{
- // 登录im
- [[XYIMBaseManager sharedInstance] im_loginWithToken:[XYUserInfoManager nowUser].rtmToken complete:^(BOOL success) {
- dispatch_group_leave(group);
- }];
- });
-
- NSString *deviceId = [CloudPushSDK getDeviceId];
- if (StringIsNotEmpty(deviceId)) {
- dispatch_group_enter(group);
- dispatch_async(queue, ^{
- // 推送注册设备
- [[XYConfigAPIManager new] registerDeviceWithDeviceId:deviceId successHandler:^(ZYLResponseModel *responseModel) {
- dispatch_group_leave(group);
- } failureHandler:^(ZYLNetworkError *error) {
- dispatch_group_leave(group);
- }];
- });
- }
- dispatch_group_notify(group, queue, ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- [[YQAnmationResourceMag sharedInstance] bagGetGiftList];
- !block?:block(YES);
- });
- });
- }
- /// 退出登录
- - (void)logoutHandleSuccess:(void(^ _Nullable)(BOOL success))block {
- // 1.修改本地登录状态
- User *nowUser = [DataBase nowUser];
- nowUser.loginStatus = 0;
- [DataBase commitDataBase];
-
- [[XYUserInfoManager sharedInstance] userLogoutBlock:nil];
- // 动态、派单未读数量重置
- [[XYIMUnReadCountManager sharedInstance] reset];
-
- // 2.IM退出
- if ([XYChatRoomManager sharedInstance].isChatRooming) {
- [[XYChatRoomManager sharedInstance] closeChatRoomBlock:^{
- [[XYIMBaseManager sharedInstance] im_logoutComplete:^(BOOL success) {
- // 2.2发送刷新UI通知
- [NotificationCenter postNotificationName:USER_LOGIN_STATUS_NOTIFICATION object:nil];
- [[self getCurrentController].navigationController popToRootViewControllerAnimated:NO];
- !block?:block(YES);
- }];
- }];
- }else {
- [[XYIMBaseManager sharedInstance] im_logoutComplete:^(BOOL success) {
- // 2.2发送刷新UI通知
- [NotificationCenter postNotificationName:USER_LOGIN_STATUS_NOTIFICATION object:nil];
- [[self getCurrentController].navigationController popToRootViewControllerAnimated:NO];
- !block?:block(YES);
- }];
- }
-
- // 3.隐藏tabbar消息提示
- [ApplicationDelegate.tabbarVC.tabBarController.tabBar hideBadgeOnItemIndex:(ApplicationDelegate.tabbarVC.tabBarController.viewControllers.count-2)];
- // 4.删除NSUserDefaults保存的信息
- if ([XYLiveManger shareInstance].AppLogoutBlock) {
- [XYLiveManger shareInstance].AppLogoutBlock(YES);
- }
-
- // 6.推送解绑账号
- [ApplicationDelegate push_unbindAccount:^(BOOL succes) {
-
- }];
- [Bugly setUserIdentifier:@"1000000"];//Bugly默认用户标示,统计进入首页之前的crash
- }
- @end
|