| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- //
- // BGBaseAppDelegate.m
- // CommonLibrary
- //
- // Created by Alexi on 3/6/14.
- // Copyright (c) 2014 CommonLibrary. All rights reserved.
- //
- #import "BGBaseAppDelegate.h"
- #import <objc/runtime.h>
- #import "PathUtility.h"
- #import "NetworkUtility.h"
- #import "NavigationViewController.h"
- @implementation BGBaseAppDelegate
- + (instancetype)sharedAppDelegate
- {
- return [UIApplication sharedApplication].delegate;
- }
- - (void)redirectConsoleLog:(NSString *)logFile
- {
- NSString *cachePath = [PathUtility getCachePath];
- NSString *logfilePath = [NSString stringWithFormat:@"%@/%@", cachePath, logFile];
- freopen([logfilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
- }
- // 配置App中的控件的默认属性
- - (void)configAppearance
- {
- // [[UINavigationBar appearance] setBarTintColor:kNavBarThemeColor];
- // [[UINavigationBar appearance] setTintColor:kWhiteColor];
-
- NSShadow *shadow = [[NSShadow alloc] init];
- shadow.shadowColor = kWhiteColor;
- shadow.shadowOffset = CGSizeMake(0, 0);
- [[UINavigationBar appearance] setTitleTextAttributes:@{
- NSForegroundColorAttributeName:kWhiteColor,
- NSShadowAttributeName:shadow,
- NSFontAttributeName:kAppLargeTextFont
- }];
-
- [[UILabel appearance] setBackgroundColor:kClearColor];
- [[UILabel appearance] setTextColor:kAppGrayColor1];
-
- [[UIButton appearance] setTitleColor:kAppGrayColor1 forState:UIControlStateNormal];
-
- // [[UITableViewCell appearance] setBackgroundColor:kClearColor];
- //
- // [[UITableViewCell appearance] setTintColor:kNavBarThemeColor];
- }
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- [self configAppearance];
-
- // 日志重定向处理
- if ([self needRedirectConsole])
- {
- //实例化一个NSDateFormatter对象
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- //设定时间格式,这里可以设置成自己需要的格式
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- //用[NSDate date]可以获取系统当前时间
- NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
-
- [self redirectConsoleLog:[NSString stringWithFormat:@"%@.log", currentDateStr]];
- }
-
- // 用StoryBoard不需要自己创建
- _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- _window.backgroundColor = [UIColor whiteColor];
-
- [self configAppLaunch];
-
- // 进入登录界面
- [self enterLoginUI];
- [_window makeKeyAndVisible];
- return YES;
- }
- - (void)configAppLaunch
- {
- // 作App配置
- [[NetworkUtility sharedNetworkUtility] startCheckWifi];
- }
- - (void)enterLoginUI
- {
- // 未提过前面的过渡界面,暂时先这样处理
- // 进入登录界面
- }
- - (BOOL)needRedirectConsole
- {
- return NO;
- }
- - (void)enterMainUI
- {
- NSLog(@"==");
- }
- // 获取当前活动的navigationcontroller
- - (UINavigationController *)navigationViewController
- {
- UIWindow *window = self.window;
-
- if ([window.rootViewController isKindOfClass:[UINavigationController class]])
- {
- UINavigationController *nav = (UINavigationController *)window.rootViewController;
-
- if (@available(iOS 15.0, *)) {
- UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
- appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
- appearance.backgroundColor = kWhiteColor;
- nav.navigationBar.scrollEdgeAppearance = appearance;
- }
-
-
- return nav;
- }
- else if ([window.rootViewController isKindOfClass:[UITabBarController class]])
- {
- UIViewController *selectVc = [((UITabBarController *)window.rootViewController) selectedViewController];
- if ([selectVc isKindOfClass:[UINavigationController class]])
- {
- UINavigationController *nav = (UINavigationController *)selectVc;
-
- if (@available(iOS 15.0, *)) {
- UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
- appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
- appearance.backgroundColor = kWhiteColor;
- nav.navigationBar.scrollEdgeAppearance = appearance;
- }
-
-
-
- return nav;
- }
- }
- return nil;
- }
- - (UIViewController *)topViewController
- {
- UINavigationController *nav = [self navigationViewController];
-
-
- return nav.topViewController;
- }
- - (UIViewController *)theTopviewControler{
- //获取根控制器
- UIViewController *rootVC = [[UIApplication sharedApplication].delegate window].rootViewController;
-
- UIViewController *parent = rootVC;
- //遍历 如果是presentViewController
- while ((parent = rootVC.presentedViewController) != nil ) {
- rootVC = parent;
- }
-
- while ([rootVC isKindOfClass:[UINavigationController class]]) {
- rootVC = [(UINavigationController *)rootVC topViewController];
- }
- return rootVC;
- }
- - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
- @autoreleasepool
- {
- viewController.hidesBottomBarWhenPushed = YES;
-
- [[self navigationViewController] pushViewController:viewController animated:animated];
-
- if (@available(iOS 15.0, *)) {
- UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
- appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
- [self navigationViewController].navigationBar.scrollEdgeAppearance = appearance;
- }
- }
- }
- - (void)pushViewController:(UIViewController *)viewController withBackTitle:(NSString *)title
- {
- @autoreleasepool
- {
- viewController.hidesBottomBarWhenPushed = YES;
- [[self navigationViewController] pushViewController:viewController withBackTitle:title animated:NO];
- }
- }
- //- (void)pushViewController:(UIViewController *)viewController withBackTitle:(NSString *)title backAction:(FWVoidBlock)action
- //{
- // @autoreleasepool
- // {
- // viewController.hidesBottomBarWhenPushed = YES;
- // [[self navigationViewController] pushViewController:viewController withBackTitle:title action:action animated:NO];
- // }
- //}
- - (UIViewController *)popViewController
- {
- return [[self navigationViewController] popViewControllerAnimated:NO];
- }
- - (NSArray *)popToRootViewController
- {
- return [[self navigationViewController] popToRootViewControllerAnimated:NO];
- }
- - (NSArray *)popToViewController:(UIViewController *)viewController
- {
- return [[self navigationViewController] popToViewController:viewController animated:NO];
- }
- - (void)presentViewController:(UIViewController *)vc animated:(BOOL)animated completion:(void (^)())completion
- {
- UIViewController *top = [self topViewController];
-
- if (vc.navigationController == nil)
- {
- NavigationViewController *nav = [[NavigationViewController alloc] initWithRootViewController:vc];
- if (@available(iOS 15.0, *)) {
- UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
- appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
- appearance.backgroundColor = kWhiteColor;
- nav.navigationBar.scrollEdgeAppearance = appearance;
- }
-
- [top presentViewController:nav animated:animated completion:completion];
- }
- else
- {
- [top presentViewController:vc animated:animated completion:completion];
- }
- }
- - (void)dismissViewController:(UIViewController *)vc animated:(BOOL)animated completion:(void (^)())completion
- {
- if (vc.navigationController != [BGBaseAppDelegate sharedAppDelegate].navigationViewController)
- {
- [vc dismissViewControllerAnimated:YES completion:nil];
- }
- else
- {
- [self popViewController];
- }
- }
- @end
|