You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
0 B

2 years ago
//
// UITabBarViewController.m
// myWatch
//
// Created by mobao on 15/10/9.
// Copyright (c) 2015xTT. All rights reserved.
//
#import "MyTabBarViewController.h"
#import "AppDelegate.h"
#import "myHelper.h"
#import "MyMQTT.h"
#import "User.h"
#import "JCManager.h"
#import "WatchHomeViewController.h"
#import "MoreViewController.h"
#import "DiscoverViewController.h"
#import "DeviceTabViewController.h"
#import "MapViewController.h"
#import "LoginViewController.h"
#import "PhoneLoginViewController.h"
#import "ForgetPwdViewController.h"
#import "RegisteredViewController.h"
2 years ago
@interface MyTabBarViewController ()<UITabBarControllerDelegate,MyTabBarDelegate>{
2 years ago
UIView *launchView;
NSString *LaunchImageName;
}
//@property (nonatomic ,strong)WCADView *adView ;
@property(nonatomic, strong) UIImageView *launchImageView;
@property (nonatomic,strong) UIImageView *bottomView;
@property (nonatomic,strong) UIWindow *subWin;
//@property (nonatomic,strong) GDTSplashAd *splash;
@property (nonatomic,strong) UIImageView *TransitionImageView;
@property (nonatomic ,strong) MapViewController *mapvc;
2 years ago
@end
@implementation MyTabBarViewController
- (void)viewDidLoad
{
2 years ago
[super viewDidLoad];
if (@available(iOS 15.0, *))
{
UITabBarAppearance *barAppearance = [[UITabBarAppearance alloc] init];
barAppearance.backgroundEffect = nil;
self.tabBar.scrollEdgeAppearance = barAppearance;
self.tabBar.standardAppearance = barAppearance;
}
else
{
// Fallback on earlier versions
[UITabBar appearance].translucent = NO;
}
2 years ago
[self addNotification];
self.delegate = self;
self.mytabbar = [MyTabBar new];
self.mytabbar.coutn = 0;
self.mytabbar.myTabBarDelegate = self;
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"WatchHomeViewController"];
[self addCustomChildVC:vc title:@"首页" imageName:@"icon_home" selectImageName:@"icon_home_select"];
[self addCustomChildVC:[DeviceTabViewController new] title:@"设备" imageName:@"icon_device" selectImageName:@"icon_device_select"];
self.mapvc = [sb instantiateViewControllerWithIdentifier:@"MapViewController"];
[self addCustomChildVC:self.mapvc title:@"定位" imageName:@"" selectImageName:@""];
[self addCustomChildVC:[[DiscoverViewController alloc] init] title:@"发现" imageName:@"icon_find" selectImageName:@"icon_find_select"];
//UIViewController *myVc = [sb instantiateViewControllerWithIdentifier:@"MyViewController"];
[self addCustomChildVC:[MoreViewController new] title:@"我的" imageName:@"icon_my" selectImageName:@"icon_my_select"];
[self setValue:self.mytabbar forKey:@"tabBar"];
2 years ago
if(!cUser){
return;
}
CGSize viewSize = self.view.bounds.size;
NSString *viewOrientation = @"Portrait"; //横屏请设置成 @"Landscape"
NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
for (NSDictionary* dict in imagesDict)
{
CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]])
{
LaunchImageName = dict[@"UILaunchImageName"];
}
}
if(!LaunchImageName)
{
2 years ago
if(ScreenHeight >= 812){
LaunchImageName = @"启动图X";
}else{
LaunchImageName = @"启动图";
}
}
//MARK: 有时会在首页显示之后再显示广告, 就是闪现首页,所以这里加个 View 做下过渡 会在首页加载完成数据后删除
_TransitionImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
_TransitionImageView.image = [UIImage imageNamed:LaunchImageName];
[self.view addSubview: _TransitionImageView];
}
- (void)tabbarClickButton:(NSInteger)index
{
self.selectedIndex = index;
if (cUser.myDevices.count <= 0)
{
//要跳 定位页面
WEAKSELF
weakSelf.selectedIndex = 0;
self.mytabbar.buttonSelectON = NO;
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"绑定设备" message:@"未绑定设备,是否前往绑定?" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
// add by lsz 2020-07-13
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil];
UINavigationController *vc = [sb instantiateViewControllerWithIdentifier:@"ScanCodeViewController"];
UINavigationController *homeNav = (UINavigationController*)weakSelf.viewControllers.firstObject;
//获取 首页的 UINavigationController
[homeNav pushViewController:vc animated:YES];
} cancelHandler:nil destructiveHandler:nil];
[alertView showAnimated:YES completionHandler:nil];
}
}
- (void)addCustomChildVC:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)imageName selectImageName:(NSString *)selectImageName
{
vc.tabBarItem.title = title;
vc.tabBarItem.image = [UIImage imageNamed:imageName];
vc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
ZXNavigationBarNavigationController *nav = [[ZXNavigationBarNavigationController alloc] initWithRootViewController:vc];
[self addChildViewController:nav];
}
2 years ago
- (void)addNotification{
[[NSNotificationCenter defaultCenter] addObserverForName:@"outLogin"
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull note)
{
if(!cUser){
//如果 outLogin 推送前 用户信息已经没有了,那么就是 token无效的场景,清除密码
[UserDefaults setBool:NO forKey:kifRememberPWDKey];
[UserDefaults removeObjectForKey:@"lastpwd"];
}
//清空推送角标
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[User setCurrentUser:nil];
//如果有菊风设备的,退出菊风SDK的推送
[[JCManager shared] uninitialize];
//退出登录,清除每天第一次登陆的记录
[UserDefaults removeObjectForKey:FirstEveryDayKey];
[self goLoginVCWithAnimate:YES];
if (self->launchView) {
2 years ago
[UIView animateWithDuration:1.0f animations:^{
self->launchView.alpha = 0.0f;
2 years ago
} completion:^(BOOL finished) {
[self->launchView removeFromSuperview];
self->launchView = nil;
2 years ago
}];
}
}];
[[NSNotificationCenter defaultCenter] addObserverForName:PUSH_type_chatGroupDisband
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull note)
{
if (!cUser) {
return;
}
if ([cUser.openid isEqualToString:note.object[@"operator"]]) {
[SVProgressHUD showSuccessWithStatus:@"该设备已经恢复出厂设置"];
[cUser localDeleteDevice];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"lastLoginName"];
[[NSUserDefaults standardUserDefaults] synchronize];
sleep(1);
[self goLoginVCWithAnimate:YES];
}else{
//如果是关注的设备,被管理员 恢复出厂设置了,需要清空一下聊天群,然后回到主页面重新 刷新数据
//清空 一下 聊天群组
cUser.chatGroups = nil;
[self setSelectedIndex:0];
UINavigationController *navVC = (UINavigationController*)self.selectedViewController;
[navVC popToRootViewControllerAnimated:YES];
}
}];
}
- (void)goLoginVCWithAnimate:(BOOL)animate{
//清空通知栏消息
//要先把BadgeNumber 设成跟当前不同的值,然后再设成0,就欧了;
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
if(![[self getCurrentVC] isKindOfClass:[LoginViewController class]] &&
![[self getCurrentVC] isKindOfClass:[PhoneLoginViewController class]] &&
![[self getCurrentVC] isKindOfClass:[ForgetPwdViewController class]] &&
![[self getCurrentVC] isKindOfClass:[RegisteredViewController class]])
{
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
[app showRootViewController];
}
// UINavigationController *vc = [addDeviceSB instantiateViewControllerWithIdentifier:@"LoginNav"];
// vc.modalPresentationStyle = UIModalPresentationFullScreen;
// [self presentViewController:vc animated:animate completion:^{
// [self.viewControllers enumerateObjectsUsingBlock:^(__kindof UINavigationController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// UIViewController *vc = [obj.viewControllers firstObject];
// [vc.navigationController popToRootViewControllerAnimated:YES];
// }];
//
// if (self.selectedIndex != 0) {
// self.selectedIndex = 0;
// }
// }];
2 years ago
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
self.mytabbar.buttonSelectON = self.selectedIndex == 2 ? YES : NO;
2 years ago
}
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
ZXNavigationBarNavigationController *selectNav = (ZXNavigationBarNavigationController*)viewController;
if (cUser.myDevices.count <= 0 && [NSStringFromClass([selectNav.topViewController class]) isEqualToString:@"DeviceTabViewController"])
{
2 years ago
//要跳 定位页面
WEAKSELF
weakSelf.selectedIndex = 0;
2 years ago
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"绑定设备" message:@"未绑定设备,是否前往绑定?" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
// add by lsz 2020-07-13
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LoginStoryboard" bundle:nil];
UINavigationController *vc = [sb instantiateViewControllerWithIdentifier:@"ScanCodeViewController"];
UINavigationController *homeNav = (UINavigationController*)weakSelf.viewControllers.firstObject;
//获取 首页的 UINavigationController
[homeNav pushViewController:vc animated:YES];
} cancelHandler:nil destructiveHandler:nil];
[alertView showAnimated:YES completionHandler:nil];
return NO;
}
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)removeTransitionImageView
{
if(_TransitionImageView){
// xLog(@"开始-0----------");
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self->_TransitionImageView.alpha = 0.0f;
} completion:^(BOOL finished) {
if(finished){
// xLog(@"结束-----------finished:%d",finished);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self->_TransitionImageView removeFromSuperview];
self->_TransitionImageView = nil;
});
}
}];
}
}
- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
+ (void)load
{
// 获取当前类的tabBarItem
UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
NSMutableDictionary *attrnor = [NSMutableDictionary dictionary];
attrnor[NSFontAttributeName] = Font_(11);
[item setTitleTextAttributes:attrnor forState:UIControlStateNormal];
}
2 years ago
//获取当前屏幕显示的viewcontroller
- (UIViewController *)getCurrentVC
{
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *currentVC = [self getCurrentVCFrom:rootViewController];
return currentVC;
}
- (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC
{
UIViewController *currentVC;
if ([rootVC presentedViewController])
{
// 视图是被presented出来的
rootVC = [rootVC presentedViewController];
}
if ([rootVC isKindOfClass:[UITabBarController class]])
{
// 根视图为UITabBarController
currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]];
}
else if ([rootVC isKindOfClass:[UINavigationController class]])
{
// 根视图为UINavigationController
currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]];
}
else
{
// 根视图为非导航类
currentVC = rootVC;
}
return currentVC;
}
2 years ago
@end