GlobalMethod+Version.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // GlobalMethod+Version.m
  3. // 乐销
  4. //
  5. // Created by 隋林栋 on 2016/12/15.
  6. // Copyright © 2016年 ping. All rights reserved.
  7. //
  8. #import "GlobalMethod+Version.h"
  9. //tabvc
  10. #import "CustomTabBarController.h"
  11. //window
  12. #import "xingchuangke-Swift.h"
  13. //baseNav
  14. #import "BaseNavController.h"
  15. @implementation GlobalMethod (Version)
  16. //注销
  17. + (void)logoutSuccess{
  18. //logout
  19. //清空数据
  20. [self clearUserInfo];
  21. //重置根视图
  22. // [self createRootNav];
  23. }
  24. //清除全局数据
  25. + (void)clearUserInfo{
  26. //clear user global data
  27. GlobalData * gbData = [GlobalData sharedInstance];
  28. gbData.GB_UserModel = nil;
  29. gbData.GB_Key = nil;
  30. //clear user default
  31. [self clearUserDefault];
  32. //clear hyphen data
  33. [[UIApplication sharedApplication] unregisterForRemoteNotifications];
  34. [[NSNotificationCenter defaultCenter] removeObserver:self];
  35. [GlobalMethod zeroIcon];
  36. }
  37. + (void)relogin{
  38. //重新登陆
  39. [GlobalMethod clearUserInfo];
  40. if (![GB_Nav.lastVC isKindOfClass:[LoginViewController class]]) {
  41. [GlobalMethod showAlert:@"登陆已过期,请重新登陆"];
  42. [GlobalMethod createRootNav];
  43. }
  44. }
  45. //判断是否登陆
  46. +(BOOL)isLoginSuccess{
  47. return [GlobalData sharedInstance].GB_Key.length > 0;
  48. }
  49. + (void)loginWithBlock:(void (^)(void))block {
  50. if ([self isLoginSuccess]) {
  51. block();
  52. }else{
  53. [GB_Nav pushViewController:[LoginViewController new] animated:true];
  54. // LoginView * loginView = [[[NSBundle mainBundle]loadNibNamed:@"LoginView" owner:self options:nil]lastObject];
  55. // loginView.blockLoginSuccess = block;
  56. // loginView.frame = CGRectMake(0, 0, screenWidth, screenHeight);
  57. // [GB_Nav.view addSubview:loginView];
  58. // loginView.blockLoginSuccess();
  59. }
  60. }
  61. //输入默认通知列表
  62. + (void)writeOriginNoticeList{
  63. if (![self isLoginSuccess]) {
  64. return;
  65. }
  66. if (![GlobalMethod readBoolLocal:LOCAL_LOGIN_BEFORE]){
  67. [GlobalMethod writeBool:YES local:LOCAL_LOGIN_BEFORE];
  68. NSMutableArray * aryLocal = [NSMutableArray array];
  69. //case 1// @"订单"; 2// @"财务"; 3// @"发货"; 4// @"审批"; 5// @"计划"; 6// @"通知"; 7 支付通知 8 支付凭证 10// @"小秘书";
  70. NSArray * aryBsort = @[@7,@8];
  71. for (int i = 0; i< aryBsort.count ; i++) {
  72. // NSNumber * num = aryBsort[i];
  73. // ModelComNoticeListItem * model = [ModelComNoticeListItem new];
  74. // model.nType = [num doubleValue];
  75. // [aryLocal addObject:model];
  76. }
  77. [GlobalMethod writeAry:aryLocal key:LOCAL_NOTICE_LIST];
  78. }
  79. }
  80. //创建rootNav
  81. + (void)createRootNav{
  82. MainNavigationController * navMain = [[MainNavigationController alloc]initWithRootViewController:[CustomTabBarController new]];
  83. navMain.navigationBarHidden = YES;
  84. GB_Nav = navMain;
  85. UIWindow * window = [UIApplication sharedApplication].keyWindow;
  86. if (!window) {
  87. window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  88. }
  89. window.rootViewController = GB_Nav;
  90. [window setBackgroundColor:[UIColor clearColor]];
  91. [window makeKeyAndVisible];
  92. AppDelegate * delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
  93. delegate.window = window;
  94. if (![GlobalMethod isLoginSuccess]) {
  95. [GB_Nav pushViewController:[LoginViewController new] animated:true];
  96. }
  97. }
  98. //刷新tableviewVC
  99. + (void)refreshTabelVCWithView:(UIView *)view {
  100. BaseTableVC *vc= (BaseTableVC *)[view fetchVC];
  101. if (vc != nil && [vc isKindOfClass:[BaseTableVC class]]) {
  102. [vc.tableView reloadData];
  103. }
  104. }
  105. //是否可以侧滑
  106. + (BOOL)canLeftSlide{
  107. if (GB_Nav.viewControllers.count <=1) {
  108. return false;
  109. }
  110. for (UIViewController * vc in GB_Nav.viewControllers) {
  111. if ([vc isKindOfClass:[LoginViewController class]]) {
  112. return false;
  113. }
  114. }
  115. return true;
  116. }
  117. // 异步执行
  118. + (void)asynthicBlock:(void (^)(void))block{
  119. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
  120. }
  121. // 异步执行
  122. + (void)mainQueueBlock:(void (^)(void))block{
  123. dispatch_async(dispatch_get_main_queue(), block);
  124. }
  125. //重复执行次数
  126. +(void)applyRepeatNum:(int)num block:(void(^)(size_t time))block{
  127. dispatch_apply(num,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),block);
  128. }
  129. //show test alert
  130. + (void)showTestAlert:(NSString *)alert{
  131. #ifdef SLD_TEST_ALERT
  132. UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"" message:UnPackStr(alert) delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
  133. [alertView show ];
  134. #endif
  135. }
  136. /**
  137. 跳转到指定根视图
  138. @param index tabbarItem数值
  139. @param animated 是否有动画
  140. */
  141. +(void)jumpToRootVC:(NSUInteger)index animated:(BOOL)animated{
  142. [GB_Nav popToRootViewControllerAnimated:false];
  143. CustomTabBarController *tabBar = GB_Nav.viewControllers.firstObject;
  144. if ([tabBar isKindOfClass:[CustomTabBarController class]]) {
  145. if (tabBar.selectedIndex != index) {
  146. [tabBar setSelectedIndex:index];
  147. }
  148. }
  149. }
  150. @end