123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- //
- // GlobalMethod+Version.m
- // 乐销
- //
- // Created by 隋林栋 on 2016/12/15.
- // Copyright © 2016年 ping. All rights reserved.
- //
- #import "GlobalMethod+Version.h"
- //tabvc
- #import "CustomTabBarController.h"
- //window
- #import "xingchuangke-Swift.h"
- //baseNav
- #import "BaseNavController.h"
- @implementation GlobalMethod (Version)
- //注销
- + (void)logoutSuccess{
- //logout
-
- //清空数据
- [self clearUserInfo];
- //重置根视图
- // [self createRootNav];
- }
- //清除全局数据
- + (void)clearUserInfo{
-
- //clear user global data
- GlobalData * gbData = [GlobalData sharedInstance];
- gbData.GB_UserModel = nil;
- gbData.GB_Key = nil;
- //clear user default
- [self clearUserDefault];
-
- //clear hyphen data
- [[UIApplication sharedApplication] unregisterForRemoteNotifications];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [GlobalMethod zeroIcon];
- }
- + (void)relogin{
- //重新登陆
- [GlobalMethod clearUserInfo];
- if (![GB_Nav.lastVC isKindOfClass:[LoginViewController class]]) {
- [GlobalMethod showAlert:@"登陆已过期,请重新登陆"];
- [GlobalMethod createRootNav];
- }
- }
- //判断是否登陆
- +(BOOL)isLoginSuccess{
- return [GlobalData sharedInstance].GB_Key.length > 0;
- }
- + (void)loginWithBlock:(void (^)(void))block {
- if ([self isLoginSuccess]) {
- block();
- }else{
- [GB_Nav pushViewController:[LoginViewController new] animated:true];
- // LoginView * loginView = [[[NSBundle mainBundle]loadNibNamed:@"LoginView" owner:self options:nil]lastObject];
- // loginView.blockLoginSuccess = block;
- // loginView.frame = CGRectMake(0, 0, screenWidth, screenHeight);
- // [GB_Nav.view addSubview:loginView];
- // loginView.blockLoginSuccess();
- }
-
- }
- //输入默认通知列表
- + (void)writeOriginNoticeList{
- if (![self isLoginSuccess]) {
- return;
- }
- if (![GlobalMethod readBoolLocal:LOCAL_LOGIN_BEFORE]){
- [GlobalMethod writeBool:YES local:LOCAL_LOGIN_BEFORE];
- NSMutableArray * aryLocal = [NSMutableArray array];
- //case 1// @"订单"; 2// @"财务"; 3// @"发货"; 4// @"审批"; 5// @"计划"; 6// @"通知"; 7 支付通知 8 支付凭证 10// @"小秘书";
- NSArray * aryBsort = @[@7,@8];
- for (int i = 0; i< aryBsort.count ; i++) {
- // NSNumber * num = aryBsort[i];
- // ModelComNoticeListItem * model = [ModelComNoticeListItem new];
- // model.nType = [num doubleValue];
- // [aryLocal addObject:model];
- }
- [GlobalMethod writeAry:aryLocal key:LOCAL_NOTICE_LIST];
- }
- }
- //创建rootNav
- + (void)createRootNav{
- MainNavigationController * navMain = [[MainNavigationController alloc]initWithRootViewController:[CustomTabBarController new]];
- navMain.navigationBarHidden = YES;
- GB_Nav = navMain;
-
- UIWindow * window = [UIApplication sharedApplication].keyWindow;
- if (!window) {
- window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- }
- window.rootViewController = GB_Nav;
- [window setBackgroundColor:[UIColor clearColor]];
- [window makeKeyAndVisible];
-
- AppDelegate * delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
- delegate.window = window;
- if (![GlobalMethod isLoginSuccess]) {
- [GB_Nav pushViewController:[LoginViewController new] animated:true];
- }
- }
- //刷新tableviewVC
- + (void)refreshTabelVCWithView:(UIView *)view {
- BaseTableVC *vc= (BaseTableVC *)[view fetchVC];
- if (vc != nil && [vc isKindOfClass:[BaseTableVC class]]) {
- [vc.tableView reloadData];
- }
- }
- //是否可以侧滑
- + (BOOL)canLeftSlide{
- if (GB_Nav.viewControllers.count <=1) {
- return false;
- }
- for (UIViewController * vc in GB_Nav.viewControllers) {
- if ([vc isKindOfClass:[LoginViewController class]]) {
- return false;
- }
- }
- return true;
- }
- // 异步执行
- + (void)asynthicBlock:(void (^)(void))block{
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
- }
- // 异步执行
- + (void)mainQueueBlock:(void (^)(void))block{
- dispatch_async(dispatch_get_main_queue(), block);
- }
- //重复执行次数
- +(void)applyRepeatNum:(int)num block:(void(^)(size_t time))block{
- dispatch_apply(num,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),block);
- }
- //show test alert
- + (void)showTestAlert:(NSString *)alert{
- #ifdef SLD_TEST_ALERT
- UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"" message:UnPackStr(alert) delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
- [alertView show ];
- #endif
- }
- /**
- 跳转到指定根视图
-
- @param index tabbarItem数值
- @param animated 是否有动画
- */
- +(void)jumpToRootVC:(NSUInteger)index animated:(BOOL)animated{
-
- [GB_Nav popToRootViewControllerAnimated:false];
- CustomTabBarController *tabBar = GB_Nav.viewControllers.firstObject;
- if ([tabBar isKindOfClass:[CustomTabBarController class]]) {
- if (tabBar.selectedIndex != index) {
- [tabBar setSelectedIndex:index];
- }
- }
- }
- @end
|