2021-09-07 23:05:43 +08:00
|
|
|
|
//
|
|
|
|
|
// ViewController.m
|
|
|
|
|
// xplan-ios
|
|
|
|
|
//
|
|
|
|
|
// Created by zu on 2021/8/31.
|
|
|
|
|
//
|
|
|
|
|
#import <UIKit/UIKit.h>
|
2021-09-13 14:22:51 +08:00
|
|
|
|
///Third
|
|
|
|
|
#import <flutter_boost/FlutterBoost.h>
|
2021-10-21 12:01:21 +08:00
|
|
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
2021-10-21 20:05:30 +08:00
|
|
|
|
#import <NIMSDK/NIMSDK.h>
|
2021-09-13 14:22:51 +08:00
|
|
|
|
///Tool
|
|
|
|
|
#import "XPMacro.h"
|
|
|
|
|
#import "ThemeColor.h"
|
|
|
|
|
#import "UIImage+Utils.h"
|
2021-09-15 18:41:40 +08:00
|
|
|
|
#import "XCHUDTool.h"
|
2021-09-26 20:42:33 +08:00
|
|
|
|
#import "AccountInfoStorage.h"
|
2021-10-21 12:01:21 +08:00
|
|
|
|
///Model
|
|
|
|
|
#import "AccountModel.h"
|
2021-09-13 14:22:51 +08:00
|
|
|
|
///VC
|
2021-09-07 23:05:43 +08:00
|
|
|
|
#import "TabbarViewController.h"
|
|
|
|
|
#import "BaseViewController.h"
|
|
|
|
|
#import "LoginViewController.h"
|
2021-09-14 21:01:09 +08:00
|
|
|
|
#import "BaseNavigationController.h"
|
|
|
|
|
#import "LoginBindPhoneViewController.h"
|
|
|
|
|
#import "LoginFullInfoViewController.h"
|
2021-09-16 17:21:52 +08:00
|
|
|
|
#import "XplanFBFlutterViewContainer.h"
|
2021-09-16 19:30:22 +08:00
|
|
|
|
#import "XPMineViewController.h"
|
2021-11-26 20:25:23 +08:00
|
|
|
|
#import "SessionListViewController.h"
|
2021-09-13 14:22:51 +08:00
|
|
|
|
///Present
|
2021-09-07 23:05:43 +08:00
|
|
|
|
#import "MainPresenter.h"
|
|
|
|
|
#import "MainProtocol.h"
|
2021-09-13 14:22:51 +08:00
|
|
|
|
|
|
|
|
|
|
2021-09-07 23:05:43 +08:00
|
|
|
|
|
2021-10-21 20:05:30 +08:00
|
|
|
|
@interface TabbarViewController () <BaseMvpProtocol, MainProtocol, NIMLoginManagerDelegate>
|
2021-09-07 23:05:43 +08:00
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) MainPresenter *presenter;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation TabbarViewController
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
[self configTheme];
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[self initTabs:NO];
|
2021-10-21 20:05:30 +08:00
|
|
|
|
|
|
|
|
|
[[NIMSDK sharedSDK].loginManager addDelegate:self];
|
2021-11-01 17:17:56 +08:00
|
|
|
|
[self.presenter juliandAdCallBackApi];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
|
[super viewWillAppear:animated];
|
2021-09-14 17:20:05 +08:00
|
|
|
|
[self.navigationController setNavigationBarHidden:YES animated:YES];
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[self.presenter autoLogin];
|
2021-10-21 20:05:30 +08:00
|
|
|
|
[self.presenter checkTranscation];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (MainPresenter *)presenter {
|
|
|
|
|
if (_presenter == nil) {
|
|
|
|
|
_presenter = [[MainPresenter alloc] init];
|
|
|
|
|
[_presenter attatchView:self];
|
|
|
|
|
}
|
|
|
|
|
return _presenter;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 20:05:30 +08:00
|
|
|
|
/** 登录成功(通过token且换取ticket后)。
|
|
|
|
|
|
|
|
|
|
1. 登录云信。
|
|
|
|
|
2. 获取用户信息。
|
|
|
|
|
3. 其实目前多余回调V层,可以在P层里自行做这个逻辑。
|
|
|
|
|
*/
|
2021-09-14 16:57:13 +08:00
|
|
|
|
- (void)autoLoginSuccess {
|
2021-10-21 20:05:30 +08:00
|
|
|
|
[self.presenter loginNIM];
|
2021-09-14 16:57:13 +08:00
|
|
|
|
[self.presenter getUserInfo];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 获取用户信息后检查:1、是否绑定手机号;2、是否需要完善用户信息。
|
2021-09-16 11:30:03 +08:00
|
|
|
|
/// 该逻辑仅在刷新ticket后执行一次。
|
2021-09-14 16:57:13 +08:00
|
|
|
|
/// 当前服务端接口是有未完善信息的全局拦截的,在BaseMvpPresenter里会触发1415去完善用户信息。
|
|
|
|
|
- (void)getUserInfoSuccess:(UserInfoModel *)userInfo {
|
2021-11-08 15:01:09 +08:00
|
|
|
|
///TODO : 先去掉绑定手机号 因为苹果审核会用apple 登录 无法绑定手机号 可能导致流程无法进行 导致被拒
|
|
|
|
|
// if (!userInfo.isBindPhone) {
|
|
|
|
|
// LoginBindPhoneViewController * bindPhoneVC = [[LoginBindPhoneViewController alloc] init];
|
|
|
|
|
// BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:bindPhoneVC];
|
|
|
|
|
// nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
|
|
// [self.navigationController presentViewController:nav animated:YES completion:nil];
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2021-09-14 16:57:13 +08:00
|
|
|
|
if (userInfo.nick == nil || userInfo.avatar == nil) {
|
|
|
|
|
[self completeUserInfo];
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[self initTabs:YES];
|
2021-09-14 16:57:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 20:05:30 +08:00
|
|
|
|
#pragma mark - BaseMvpProtocol
|
2021-09-07 23:05:43 +08:00
|
|
|
|
- (void)tokenInvalid {
|
|
|
|
|
LoginViewController *lvc = [[LoginViewController alloc] init];
|
2021-09-18 16:45:45 +08:00
|
|
|
|
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:lvc];
|
|
|
|
|
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
|
|
[self.navigationController presentViewController:nav animated:YES completion:nil];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)completeUserInfo {
|
2021-09-18 16:45:45 +08:00
|
|
|
|
LoginFullInfoViewController * bindPhoneVC = [[LoginFullInfoViewController alloc] init];
|
|
|
|
|
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:bindPhoneVC];
|
|
|
|
|
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
|
|
[self.navigationController presentViewController:nav animated:YES completion:nil];
|
2021-09-14 21:01:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 20:05:30 +08:00
|
|
|
|
#pragma mark - NIMLoginManagerDelegate
|
|
|
|
|
- (void)onAutoLoginFailed:(NSError *)error {
|
|
|
|
|
// 如果非上次登录设备 autoLogin 会返回 417
|
|
|
|
|
if (error.code == 417) {
|
|
|
|
|
@weakify(self);
|
|
|
|
|
AccountModel* accountModel = [AccountInfoStorage instance].getCurrentAccountInfo;
|
|
|
|
|
[[NIMSDK sharedSDK].loginManager login:accountModel.uid token:accountModel.netEaseToken completion:^(NSError * _Nullable error) {
|
|
|
|
|
if (error) {
|
|
|
|
|
@strongify(self);
|
|
|
|
|
[self.presenter logout];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[self.presenter logout];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 20:05:30 +08:00
|
|
|
|
- (void)onKickout:(NIMLoginKickoutResult *)result {
|
|
|
|
|
[self.presenter logout];
|
2021-10-21 12:01:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 23:05:43 +08:00
|
|
|
|
- (void)configTheme {
|
2021-09-13 14:22:51 +08:00
|
|
|
|
[[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[ThemeColor appCellBackgroundColor] size:CGSizeMake(KScreenWidth, kTabBarHeight)]];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
|
|
|
|
|
if (@available(iOS 10.0, *)) {
|
2021-09-13 14:22:51 +08:00
|
|
|
|
[[UITabBar appearance] setUnselectedItemTintColor:[ThemeColor tabbarNormalColor]];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-18 16:45:45 +08:00
|
|
|
|
- (void)initTabs:(BOOL)logined {
|
2021-11-26 20:25:23 +08:00
|
|
|
|
NSArray *normalImageNames = @[@"tab_game_normal", @"tab_message_normal", @"tab_mine_normal"];
|
|
|
|
|
NSArray *selectImageNames = @[@"tab_game_selected", @"tab_message_selected", @"tab_mine_selected"];
|
|
|
|
|
NSArray *tabLabel = @[@"赛事", @"消息", @"我的"];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
|
2021-09-18 16:45:45 +08:00
|
|
|
|
UIViewController *game;
|
2021-11-26 20:25:23 +08:00
|
|
|
|
UIViewController *msg;
|
2021-09-18 16:45:45 +08:00
|
|
|
|
UIViewController *me;
|
|
|
|
|
if (logined) {
|
|
|
|
|
XplanFBFlutterViewContainer *fvcGame = XplanFBFlutterViewContainer.new;
|
2021-09-08 20:28:37 +08:00
|
|
|
|
#ifdef DEBUG
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[fvcGame setName:@"debug" uniqueId:nil params:nil];
|
2021-09-08 20:28:37 +08:00
|
|
|
|
#else
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[fvcGame setName:@"/" uniqueId:nil params:nil];
|
2021-09-08 20:28:37 +08:00
|
|
|
|
#endif
|
2021-09-18 16:45:45 +08:00
|
|
|
|
game = fvcGame;
|
2021-11-26 20:25:23 +08:00
|
|
|
|
msg = [[SessionListViewController alloc] init];
|
2021-09-18 16:45:45 +08:00
|
|
|
|
me = [[XPMineViewController alloc] init];
|
|
|
|
|
} else {
|
|
|
|
|
game = [[BaseViewController alloc]init];
|
2021-12-02 20:31:29 +08:00
|
|
|
|
msg = [[SessionListViewController alloc]init];
|
2021-09-18 16:45:45 +08:00
|
|
|
|
me = [[BaseViewController alloc]init];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self createTabBarItem:game title:tabLabel[0] image:normalImageNames[0] selectedImage:selectImageNames[0]];
|
2021-11-26 20:25:23 +08:00
|
|
|
|
[self createTabBarItem:msg title:tabLabel[1] image:normalImageNames[1] selectedImage:selectImageNames[1]];
|
|
|
|
|
[self createTabBarItem:me title:tabLabel[2] image:normalImageNames[2] selectedImage:selectImageNames[2]];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
|
2021-11-26 20:25:23 +08:00
|
|
|
|
self.viewControllers = @[game, msg, me];
|
2021-09-08 20:28:37 +08:00
|
|
|
|
|
2021-09-18 16:04:50 +08:00
|
|
|
|
self.selectedIndex = 0;
|
2021-09-07 23:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:21:52 +08:00
|
|
|
|
- (BaseNavigationController *)createTabBarItem:(UIViewController *)itemVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
|
2021-09-07 23:05:43 +08:00
|
|
|
|
itemVc.title = title;
|
|
|
|
|
itemVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
|
|
|
|
itemVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
2021-09-13 14:22:51 +08:00
|
|
|
|
[itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor appMainColor]} forState:UIControlStateSelected];
|
|
|
|
|
[itemVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[ThemeColor tabbarNormalColor]} forState:UIControlStateNormal];
|
2021-09-16 17:21:52 +08:00
|
|
|
|
|
|
|
|
|
BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:itemVc];
|
|
|
|
|
return nav;
|
2021-09-07 23:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-15 18:41:40 +08:00
|
|
|
|
- (void)showSuccessToast:(NSString *)msg {
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[XCHUDTool showSuccessWithMessage:msg];
|
2021-09-15 18:41:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)showErrorToast:(NSString *)msg {
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[XCHUDTool showErrorWithMessage:msg];
|
2021-09-15 18:41:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)showLoading {
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[XCHUDTool showLoading];
|
2021-09-15 18:41:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)hideHUD {
|
2021-09-18 16:45:45 +08:00
|
|
|
|
[XCHUDTool hideHUD];
|
2021-09-15 18:41:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 23:05:43 +08:00
|
|
|
|
@end
|