123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- //
- // FLPushViewControllerHelper.m
- // FirstLink
- //
- // Created by unicode on 14-9-26.
- // Copyright (c) 2014年 FirstLink. All rights reserved.
- //
- #import "FLControllerHelper.h"
- #import "FirstLinkAppDelegate.h"
- #import "LoginViewController.h"
- #import "FKPersonOrderController.h"
- #import "FKOrderSegmentController.h"
- #import "FKMessageManager.h"
- static UIImagePickerController *imagePicker = nil;
- //static UITabBarController *globalSaveTabBarController = nil;
- #define kLoginAnimDuration 0.3f
- @implementation FLControllerHelper
- #pragma mark - Pop Login View Controller
- + (void)presentLoginViewController{
- [self presentLoginControllerAnimated:YES completion:nil];
- }
- + (void)dismissLoginViewController{
- [self dismissLoginControllerAnimated:YES completion:nil];
- }
- + (void)presentLoginControllerAnimated:(BOOL)animated completion:(completion)completion {
- FirstLinkAppDelegate *delegate = (FirstLinkAppDelegate *)[[UIApplication sharedApplication] delegate];
- if ([self isShowingLoginNavigationController]) return;
-
- UITabBarController *tabbarController = (UITabBarController*)delegate.window.rootViewController;
- LoginViewController *login = [[self currentStoryBoard] instantiateViewControllerWithIdentifier:@"LoginViewController"];
- UINavigationController *addNav = [[UINavigationController alloc]initWithRootViewController:login];
-
- UINavigationController *curNaviController = (UINavigationController*)tabbarController.selectedViewController;
- if ([curNaviController isKindOfClass:[UINavigationController class]]) {
- FLViewController *currentController = (FLViewController*)curNaviController.topViewController;
- [currentController presentViewController:addNav animated:YES completion:completion];
- }
-
- }
- + (void)dismissLoginControllerAnimated:(BOOL)animated completion:(completion)completion {
- [SystemUtil asyncRequestUserAuthority];
- [[FKMessageManager sharedInstance] refreshMessageUnreadMessage];
-
- if (![self isShowingLoginNavigationController]) return;
-
- UINavigationController *currentNav = [self currentNavigationController];
- if (currentNav.presentingViewController){
- [currentNav dismissViewControllerAnimated:animated completion:completion];
- }
-
- // 通知购物车需要更新,用户登录或者更换账号
- [[NSNotificationCenter defaultCenter] postNotificationName:BASKET_NEED_TO_REFRESH object:nil];
- }
- #pragma mark - Camera Manager
- +(void)launchAppCamera:(UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>*)viewController type:(UIImagePickerControllerSourceType)type {
- if (type == UIImagePickerControllerSourceTypeCamera && ![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
-
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil
- message:@"无法使用相机,请前往设置打开"
- delegate:nil
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil, nil];
- [alert show];
- alert = nil;
- return;
- }
- if (!imagePicker) {
- imagePicker = [[UIImagePickerController alloc] init];
- }
-
- imagePicker.allowsEditing = YES;
- imagePicker.sourceType = type;
- imagePicker.delegate = viewController;
- imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
- [viewController presentViewController:imagePicker
- animated:YES
- completion:^{
-
- }];
- }
- #pragma mark - Helper
- + (BOOL)isShowingLoginNavigationController {
- // 判断当前是否正在展示登录界面的navigation
- UINavigationController *currentNav = [self currentNavigationController];
- if (currentNav) {
- for (UIViewController *vc in currentNav.viewControllers) {
- if ([vc isKindOfClass:[LoginViewController class]]) return YES;
- }
- }
-
- return NO;
- }
- + (FLViewController *)currentController {
-
- UINavigationController *currentNav = [self currentNavigationController];
- if (currentNav) {
- return (FLViewController *)currentNav.topViewController;
- }
- return nil;
- }
- + (NSArray<FLViewController *> *)currentControllers {
- UINavigationController *currentNav = [self currentNavigationController];
- return currentNav.viewControllers;
- }
- + (UITabBarController*)currentTabBarController {
-
- FirstLinkAppDelegate *delegate = (FirstLinkAppDelegate *)[[UIApplication sharedApplication] delegate];
- id controller = delegate.window.rootViewController;
- if ([controller isKindOfClass:[UITabBarController class]]) {
- return controller;
- }
- return nil;
- }
- + (UINavigationController *)currentNavigationController{
-
- UITabBarController *tabBar = [self currentTabBarController];
- if (!tabBar) return nil;
-
- UINavigationController *selectNav = tabBar.selectedViewController;
- if ([selectNav isKindOfClass:[UINavigationController class]]){
- UINavigationController *presentNav = (UINavigationController *)selectNav.topViewController.presentedViewController;
- if ([presentNav isKindOfClass:[UINavigationController class]]) {
- return presentNav;
- }
- return selectNav;
- }
- return nil;
- }
- + (void)backToMainController
- {
- UITabBarController *tabbarController = [self currentTabBarController];
- if (!tabbarController) return;
- NSInteger selectIndex = tabbarController.selectedIndex;
- NSArray *viewControllers = tabbarController.viewControllers;
- if (viewControllers.count > 0) {
- UINavigationController *naviController = viewControllers[selectIndex];
- if ([naviController isKindOfClass:[UINavigationController class]]) {
- tabbarController.selectedIndex = 0;
- [tabbarController.tabBar setHidden:NO];
- [naviController popToRootViewControllerAnimated:YES];
- }
- }
- }
- + (void)backToOrderListController
- {
- UITabBarController *tabbarController = [self currentTabBarController];
- if (!tabbarController) return;
- NSInteger selectIndex = tabbarController.selectedIndex;
- NSArray *viewControllers = tabbarController.viewControllers;
- if (viewControllers.count > 0) {
- UINavigationController *naviController = viewControllers[selectIndex];
- if ([naviController isKindOfClass:[UINavigationController class]]) {
- NSMutableArray *arrayM = [NSMutableArray arrayWithArray:naviController.viewControllers];
- [arrayM removeObjectsInRange:NSMakeRange(1, arrayM.count - 1)];
-
- FKOrderSegmentController *controller = [[FKOrderSegmentController alloc] init];
- controller.selectedType = FKPersonOrderClassifyNonpayment;
- controller.hidesBottomBarWhenPushed = YES;
-
- [arrayM addObject:controller];
- [naviController setViewControllers:arrayM animated:YES];
- }
- }
- }
- +(void)selectTabbarControllerAtIndex:(NSInteger)index {
- UITabBarController *tabbarController = [FLControllerHelper currentTabBarController];
- if (!tabbarController) return;
- if (index < tabbarController.viewControllers.count) {
- tabbarController.selectedIndex = index;
- }
- }
- + (UIStoryboard*)currentStoryBoard {
- UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"]
- bundle:[NSBundle mainBundle]];
- return storyboard;
- }
- @end
|