XCHUDTool封装到BaseViewController
This commit is contained in:
@@ -74,4 +74,4 @@ SPEC CHECKSUMS:
|
||||
|
||||
PODFILE CHECKSUM: 82677bb54bd8940f2a6cc6f00b6eaefb58c721b7
|
||||
|
||||
COCOAPODS: 1.11.0
|
||||
COCOAPODS: 1.10.1
|
||||
|
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "BaseViewController.h"
|
||||
#import "BaseMvpProtocol.h"
|
||||
#import "HttpRequestHelper.h"
|
||||
|
||||
@@ -18,6 +19,7 @@ typedef void(^HttpFail)(NSInteger code, NSString * _Nullable msg);
|
||||
|
||||
- (void)attatchView:(id)view;
|
||||
- (id)getView;
|
||||
- (BaseViewController *)getBaseVC;
|
||||
- (void)detatchView;
|
||||
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail;
|
||||
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading;
|
||||
|
@@ -6,7 +6,6 @@
|
||||
//
|
||||
|
||||
#import "BaseMvpPresenter.h"
|
||||
#import "XCHUDTool.h"
|
||||
|
||||
@interface BaseMvpPresenter()
|
||||
|
||||
@@ -24,8 +23,12 @@
|
||||
return self.view;
|
||||
}
|
||||
|
||||
- (BaseViewController *)getBaseVC {
|
||||
return ((BaseViewController *) [self getView]);
|
||||
}
|
||||
|
||||
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail {
|
||||
return [self createHttpCompletion:success fail:fail showLoading:YES errorToast:YES];
|
||||
return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:YES];
|
||||
}
|
||||
|
||||
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading {
|
||||
@@ -33,16 +36,16 @@
|
||||
}
|
||||
|
||||
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail errorToast:(BOOL)toast {
|
||||
return [self createHttpCompletion:success fail:fail showLoading:YES errorToast:toast];
|
||||
return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:toast];
|
||||
}
|
||||
|
||||
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading errorToast:(BOOL)toast {
|
||||
if (loading) {
|
||||
[XCHUDTool showLoading];
|
||||
[[self getBaseVC] showLoading];
|
||||
}
|
||||
return ^(BaseModel *data, NSInteger code, NSString * _Nullable msg) {
|
||||
if (loading) {
|
||||
[XCHUDTool hideHUD];
|
||||
[[self getBaseVC] hideHUD];
|
||||
}
|
||||
if (code == 200) {
|
||||
success(data);
|
||||
@@ -59,7 +62,7 @@
|
||||
}
|
||||
|
||||
if (toast) {
|
||||
[XCHUDTool showErrorWithMessage:msg];
|
||||
[[self getBaseVC] showErrorToast:msg];
|
||||
}
|
||||
fail(code, msg);
|
||||
};
|
||||
|
@@ -33,6 +33,26 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
- (void)hideStatusBar;
|
||||
|
||||
/**
|
||||
成功 toast
|
||||
*/
|
||||
- (void)showSuccessToast:(NSString *)msg;
|
||||
|
||||
/**
|
||||
失败 toast
|
||||
*/
|
||||
- (void)showErrorToast:(NSString *)msg;
|
||||
|
||||
/**
|
||||
加载 loading
|
||||
*/
|
||||
- (void)showLoading;
|
||||
|
||||
/**
|
||||
隐藏 XCHUDTool
|
||||
*/
|
||||
- (void)hideHUD;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#import "BaseViewController.h"
|
||||
///Tool
|
||||
#import "XCHUDTool.h"
|
||||
#import "ThemeColor.h"
|
||||
|
||||
@interface BaseViewController ()
|
||||
@@ -54,5 +55,21 @@
|
||||
[UIApplication sharedApplication].statusBarHidden = YES;
|
||||
}
|
||||
|
||||
- (void)showSuccessToast:(NSString *)msg {
|
||||
[XCHUDTool showSuccessWithMessage:msg];
|
||||
}
|
||||
|
||||
- (void)showErrorToast:(NSString *)msg {
|
||||
[XCHUDTool showErrorWithMessage:msg];
|
||||
}
|
||||
|
||||
- (void)showLoading {
|
||||
[XCHUDTool showLoading];
|
||||
}
|
||||
|
||||
- (void)hideHUD {
|
||||
[XCHUDTool hideHUD];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
@@ -35,7 +35,7 @@
|
||||
[self openCutDownWithTotal:60];
|
||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
|
||||
} showLoading:NO errorToast:YES] mobile:phone type:[NSString stringWithFormat:@"%d", type]];
|
||||
}] mobile:phone type:[NSString stringWithFormat:@"%d", type]];
|
||||
}
|
||||
|
||||
|
||||
|
@@ -37,7 +37,7 @@
|
||||
[[self getView] phoneAndPasswordLoginSuccess];
|
||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
|
||||
}] phone:phone password:desPassword client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"];
|
||||
} showLoading:YES] phone:phone password:desPassword client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -13,7 +13,6 @@
|
||||
#import "Api+Login.h"
|
||||
///Tool
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "XCHUDTool.h"
|
||||
///P
|
||||
#import "LoginProtocol.h"
|
||||
///Model
|
||||
@@ -30,10 +29,10 @@
|
||||
- (void)phoneQuickLogin:(NSString *)accessToken token:(NSString *)token {
|
||||
[Api phoneQuickLogin:[self createHttpCompletion:^(BaseModel *data) {
|
||||
[[AccountInfoStorage instance] saveAccountInfo:[AccountModel modelWithDictionary:data.data]];
|
||||
[[self getView] phoneQuickLoginSuccess];
|
||||
[[self getView] loginSuccess];
|
||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
// todo fail
|
||||
}] accessToken:accessToken token:token];
|
||||
} showLoading:YES] accessToken:accessToken token:token];
|
||||
}
|
||||
|
||||
|
||||
@@ -81,33 +80,31 @@
|
||||
NSString * givenName = [user.credential rawData][@"fullName"][@"givenName"];
|
||||
userInfo.userName = [NSString stringWithFormat:@"%@%@", familyName, givenName];
|
||||
}
|
||||
[self thirdLOginWithopenID:openid andUnionID:unionid access_token:access_token andType:type];
|
||||
[self thirdLoginWithOpenID:openid andUnionID:unionid access_token:access_token andType:type];
|
||||
} else if(state == SSDKResponseStateCancel) {///取消
|
||||
[XCHUDTool hideHUD];
|
||||
[[self getView] thirdLoginCancel];
|
||||
[[self getBaseVC] hideHUD];
|
||||
[[self getBaseVC] showErrorToast:@"登录取消"];
|
||||
} else if (state == SSDKResponseStateFail) {///失败
|
||||
[XCHUDTool hideHUD];
|
||||
[[self getBaseVC] hideHUD];
|
||||
if (error.description) {
|
||||
[[self getView] thirdLoginFailth:error.description];
|
||||
[[self getBaseVC] showErrorToast:error.description];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)thirdLOginWithopenID:(NSString *)openId
|
||||
- (void)thirdLoginWithOpenID:(NSString *)openId
|
||||
andUnionID:(NSString *)unionID
|
||||
access_token:(NSString *)access_token
|
||||
andType:(ThirdLoginType)type {
|
||||
NSString * typeStr = [NSString stringWithFormat:@"%lu", type];
|
||||
NSString * typeStr = [NSString stringWithFormat:@"%lu", (unsigned long)type];
|
||||
unionID = @"";
|
||||
[Api loginWithThirdPartWithComplction:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||||
[XCHUDTool hideHUD];
|
||||
[[self getBaseVC] hideHUD];
|
||||
AccountModel * model = [AccountModel modelWithDictionary:data.data];
|
||||
if (model != nil) {
|
||||
[[AccountInfoStorage instance] saveAccountInfo:model];
|
||||
[[self getView] thirdLoginSuccess];
|
||||
} else {
|
||||
[[self getView] thirdLoginFailth:@"登录失败"];
|
||||
[[self getView] loginSuccess];
|
||||
}
|
||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
} showLoading:YES] openid:openId unionid:unionID access_token:access_token type:typeStr];
|
||||
|
@@ -35,7 +35,7 @@
|
||||
[self openCutDownWithTotal:60];
|
||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
|
||||
} showLoading:NO errorToast:YES] mobile:phone type:[NSString stringWithFormat:@"%d", type]];
|
||||
}] mobile:phone type:[NSString stringWithFormat:@"%d", type]];
|
||||
}
|
||||
|
||||
/// 使用手机号和验证码登录
|
||||
@@ -50,7 +50,7 @@
|
||||
[[self getView] loginSuccess];
|
||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
|
||||
}] phone:phone code:code client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"];
|
||||
} showLoading:YES] phone:phone code:code client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"];
|
||||
}
|
||||
|
||||
|
||||
|
@@ -11,14 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol LoginProtocol <NSObject>
|
||||
|
||||
- (void)phoneQuickLoginSuccess;
|
||||
|
||||
///第三方登录取消
|
||||
- (void)thirdLoginCancel;
|
||||
///第三方登录失败
|
||||
- (void)thirdLoginFailth:(NSString *)message;
|
||||
///第三方登录成功
|
||||
- (void)thirdLoginSuccess;
|
||||
- (void)loginSuccess;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -11,7 +11,6 @@
|
||||
#import <ReactiveObjC/ReactiveObjC.h>
|
||||
///Tool
|
||||
#import "ThemeColor.h"
|
||||
#import "XCHUDTool.h"
|
||||
#import "UIImage+Utils.h"
|
||||
///Presenter
|
||||
#import "LoginForgetPasswordPresent.h"
|
||||
@@ -96,7 +95,7 @@
|
||||
[[self.codeView.authCodeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
|
||||
@strongify(self);
|
||||
if (self.phoneView.textField.text.length != 11) {
|
||||
[XCHUDTool showErrorWithMessage:@"请输入正确的手机号码"];
|
||||
[self showErrorToast:@"请输入正确的手机号码"];
|
||||
} else {
|
||||
[self.presenter phoneSmsCode:self.phoneView.textField.text type:3];
|
||||
}
|
||||
@@ -113,7 +112,7 @@
|
||||
///请求手机号的验证码成功
|
||||
- (void)phoneSmsCodeSuccess {
|
||||
self.codeView.authCodeButton.enabled= NO;
|
||||
[XCHUDTool showSuccessWithMessage:@"验证码发送成功"];
|
||||
[self showSuccessToast:@"验证码发送成功"];
|
||||
}
|
||||
///倒计时进行中
|
||||
- (void)countDownWithCurrent:(int)current {
|
||||
@@ -126,7 +125,7 @@
|
||||
}
|
||||
///重置密码成功
|
||||
- (void)resetPasswrodSuccess {
|
||||
[XCHUDTool showSuccessWithMessage:@"重置密码成功"];
|
||||
[self showSuccessToast:@"重置密码成功"];
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@
|
||||
#import <Masonry/Masonry.h>
|
||||
#import <ReactiveObjC/ReactiveObjC.h>
|
||||
///Tool
|
||||
#import "XCHUDTool.h"
|
||||
#import "UIImage+Utils.h"
|
||||
#import "ThemeColor.h"
|
||||
///Presenter
|
||||
@@ -130,7 +129,7 @@
|
||||
|
||||
#pragma mark - LoginPasswordProtocol
|
||||
- (void)phoneAndPasswordLoginSuccess {
|
||||
[XCHUDTool showSuccessWithMessage:@"登录成功"];
|
||||
[self showSuccessToast:@"登录成功"];
|
||||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,6 @@
|
||||
#import <Masonry/Masonry.h>
|
||||
#import <ReactiveObjC/ReactiveObjC.h>
|
||||
///Tool
|
||||
#import "XCHUDTool.h"
|
||||
#import "ThemeColor.h"
|
||||
///Presenter
|
||||
#import "LoginVerifCodePresent.h"
|
||||
@@ -134,7 +133,7 @@
|
||||
}
|
||||
|
||||
- (void)loginSuccess {
|
||||
[XCHUDTool showSuccessWithMessage:@"登录成功"];
|
||||
[self showSuccessToast:@"登录成功"];
|
||||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,6 @@
|
||||
///Tool
|
||||
#import "UIImage+Utils.h"
|
||||
#import "GCDHelper.h"
|
||||
#import "XCHUDTool.h"
|
||||
#import "XPMacro.h"
|
||||
#import "ThemeColor.h"
|
||||
#import "XPConstant.h"
|
||||
@@ -239,7 +238,7 @@ typedef NS_ENUM(NSUInteger, XYLoginType) {
|
||||
}
|
||||
|
||||
- (void)phoneQuickLogin {
|
||||
[XCHUDTool showLoading];
|
||||
[self showLoading];
|
||||
// 在使用一键登录之前,请先调用shouldQuickLogin方法,判断当前上网卡的网络环境和运营商是否可以一键登录
|
||||
@weakify(self)
|
||||
NTESQuickLoginManager *qlManager = [NTESQuickLoginManager sharedInstance];
|
||||
@@ -281,7 +280,7 @@ typedef NS_ENUM(NSUInteger, XYLoginType) {
|
||||
//取消一键登录
|
||||
if ([resultCode isEqualToString:@"200020"] ||
|
||||
[resultCode isEqualToString:@"10104"]) {
|
||||
[XCHUDTool hideHUD];
|
||||
[self hideHUD];
|
||||
} else {
|
||||
[self phoneQuickLoginFail];
|
||||
}
|
||||
@@ -293,7 +292,7 @@ typedef NS_ENUM(NSUInteger, XYLoginType) {
|
||||
@strongify(self)
|
||||
// [TTStatisticsService trackEvent:@"one_click_login_succeed" eventDescribe:@"一键登录成功"];
|
||||
// // 取号成功,获取acessToken
|
||||
[XCHUDTool hideHUD];
|
||||
[self hideHUD];
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
[self.presenter phoneQuickLogin:resultDic[@"accessToken"] token:token];
|
||||
});
|
||||
@@ -304,7 +303,7 @@ typedef NS_ENUM(NSUInteger, XYLoginType) {
|
||||
}
|
||||
|
||||
- (void)phoneQuickLoginFail {
|
||||
[XCHUDTool showErrorWithMessage:@"一键登录失败,请检查手机网络状态。"];
|
||||
[self showErrorToast:@"一键登录失败,请检查手机网络状态。"];
|
||||
LoginPhoneViewController *inputPhoneVC = [[LoginPhoneViewController alloc] init];
|
||||
[self.navigationController pushViewController:inputPhoneVC animated:YES];
|
||||
}
|
||||
@@ -360,28 +359,16 @@ typedef NS_ENUM(NSUInteger, XYLoginType) {
|
||||
CMModel.protocolColor = [ThemeColor appMainColor];
|
||||
|
||||
CMModel.backActionBlock = ^{ //点击了返回按钮
|
||||
[XCHUDTool hideHUD];
|
||||
[self hideHUD];
|
||||
};
|
||||
dispatch_main_sync_safe(^{
|
||||
[[NTESQuickLoginManager sharedInstance] setupModel:CMModel];
|
||||
});
|
||||
}
|
||||
#pragma mark - LoginProtocol
|
||||
- (void)phoneQuickLoginSuccess {
|
||||
- (void)loginSuccess {
|
||||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
- (void)thirdLoginSuccess {
|
||||
[self.navigationController popToRootViewControllerAnimated:YES];
|
||||
[XCHUDTool showSuccessWithMessage:@"登录成功"];
|
||||
}
|
||||
|
||||
- (void)thirdLoginCancel {
|
||||
[XCHUDTool showSuccessWithMessage:@"取消登录"];
|
||||
}
|
||||
|
||||
- (void)thirdLoginFailth:(NSString *)message {
|
||||
[XCHUDTool showErrorWithMessage:message];
|
||||
[self showSuccessToast:@"登录成功"];
|
||||
}
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
|
@@ -29,7 +29,7 @@
|
||||
[[self getView] autoLoginSuccess];
|
||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
|
||||
} showLoading:NO] access_token:accountModel.access_token issue_type:@"multi"];
|
||||
}] access_token:accountModel.access_token issue_type:@"multi"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user