AppDelegate.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //
  2. // AppDelegate.m
  3. // HappyJob
  4. //
  5. // Created by Bob on 2019/3/11.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "HJLoginViewController.h"
  10. #import "HJMainViewController.h"
  11. #import "FBNetworkingConfig.h"
  12. #import "HJWeiXinAPIManager.h"
  13. #import "HJUserInfoModel.h"
  14. #import "UIButton+HJGradientButton.h"
  15. #import <IQKeyboardManager/IQKeyboardManager.h>
  16. #import <WXApi.h>
  17. #import <XHLaunchAd/XHLaunchAd.h>
  18. #import "HJWelcomeViewController.h"
  19. #import <AMapFoundationKit/AMapFoundationKit.h>
  20. #import <Bugly/Bugly.h>
  21. #import "BMainViewController.h"//自发布的
  22. #import "BReleaseJobsViewController.h"//发布工作
  23. #import "HJLoginViewController.h"//登录
  24. @interface AppDelegate () <HJWelcomeViewDelegate,UITabBarControllerDelegate>
  25. @property (nonatomic, strong) BMainViewController *bTabBarC;//自发布
  26. @property (nonatomic, strong) HJMainViewController *CTabBarC;
  27. @property (nonatomic, assign) int lastIndex;//tabBar选中的上一个的视图索引
  28. @end
  29. @implementation AppDelegate
  30. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  31. //配置Bugly
  32. [Bugly startWithAppId:kBuglyAppID];
  33. //配置广告数据
  34. [self setupAd];
  35. // 高德地图
  36. [AMapServices sharedServices].apiKey = kGAODEAPIKey;
  37. // 微信授权
  38. [WXApi registerApp:kWeiXinAPIKey];
  39. // 配置接口调用
  40. [FBNetworkingConfig sharedConfig].baseURL = kHJBaseURL;
  41. // DDTTYLogger,你的日志语句将被发送到Xcode控制台
  42. [DDLog addLogger:[DDTTYLogger sharedInstance]];
  43. // 设置键盘监听管理
  44. IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
  45. keyboardManager.toolbarDoneBarButtonItemText = @"完成";
  46. keyboardManager.shouldResignOnTouchOutside = YES;
  47. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  48. self.window.backgroundColor = [UIColor whiteColor];
  49. //引导页
  50. HJWelcomeViewController *welcomeViewController = [[HJWelcomeViewController alloc] init];
  51. welcomeViewController.delegate = self;
  52. if (welcomeViewController.isShow)
  53. {
  54. self.window.rootViewController = welcomeViewController;
  55. }
  56. else
  57. {
  58. self.window.rootViewController = [self setupFirstViewController];
  59. }
  60. [self.window makeKeyAndVisible];
  61. // //设置状态栏为白色的
  62. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
  63. return YES;
  64. }
  65. /* iOS 9 之前用 */
  66. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
  67. return [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
  68. }
  69. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  70. return [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
  71. }
  72. /* iOS 9之后用 */
  73. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  74. return [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
  75. }
  76. #pragma mark - HJWelcomeViewDelegate
  77. - (void)skipWelcomeView:(HJWelcomeViewController *)welcomeView {
  78. self.window.rootViewController = [self setupFirstViewController];
  79. }
  80. #pragma mark - event response
  81. - (void)launchStartButtonClicked:(UIButton *)sender {
  82. [XHLaunchAd removeAndAnimated:YES];
  83. }
  84. #pragma mark - private methods
  85. - (UIViewController *)setupFirstViewController {
  86. if ([HJMemberInfoModel memberInfo].memberId == nil || [[HJMemberInfoModel memberInfo].memberId isEqualToString: @""])
  87. { //c端
  88. _CTabBarC = [[HJMainViewController alloc] init];
  89. _CTabBarC.delegate = self;
  90. return _CTabBarC;
  91. }
  92. else
  93. {
  94. if (USERTYPE)
  95. { //自发布
  96. _bTabBarC = [[BMainViewController alloc]init];
  97. _bTabBarC.delegate = self;
  98. return _bTabBarC;
  99. }
  100. else
  101. { //c端
  102. _CTabBarC = [[HJMainViewController alloc] init];
  103. _CTabBarC.delegate = self;
  104. return _CTabBarC;
  105. }
  106. }
  107. }
  108. /* 推出登录 */
  109. -(void)pushLoginViewController {
  110. HJLoginViewController *loginVC=[[HJLoginViewController alloc]init];
  111. UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:loginVC];
  112. [self.window.rootViewController presentViewController:navi animated:YES completion:nil];
  113. }
  114. /* 切换身份 */
  115. - (void)switchTabBar {
  116. self.window.rootViewController = [self setupFirstViewController];
  117. }
  118. #pragma mark - UITabBarControllerDelegate 代理
  119. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
  120. {
  121. if (tabBarController == _bTabBarC)
  122. {
  123. if (_bTabBarC.tabBar.selectedItem.tag == 2 && [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 0)
  124. {//取消tabBar的点击事件
  125. return NO;
  126. }
  127. else
  128. {
  129. _lastIndex = (int)tabBarController.selectedIndex;
  130. return YES;
  131. }
  132. }
  133. else
  134. {
  135. _lastIndex = (int)tabBarController.selectedIndex;
  136. return YES;
  137. }
  138. }
  139. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
  140. {
  141. if (tabBarController == _bTabBarC)
  142. {//自发布
  143. if (tabBarController.selectedIndex == 2)
  144. {
  145. if ([[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 3 || [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 2 || [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 1)
  146. {
  147. tabBarController.selectedIndex = _lastIndex ;
  148. BReleaseJobsViewController *certification=[[BReleaseJobsViewController alloc]init];
  149. UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:certification];
  150. [self.window.rootViewController presentViewController:navi animated:YES completion:nil];
  151. }
  152. else
  153. {
  154. tabBarController.selectedIndex = _lastIndex ;
  155. }
  156. }
  157. }
  158. else
  159. {
  160. if ([HJMemberInfoModel memberInfo].memberId == nil || [[HJMemberInfoModel memberInfo].memberId isEqualToString: @""])
  161. {
  162. if( tabBarController.selectedIndex == 2 || tabBarController.selectedIndex == 3)
  163. {
  164. tabBarController.selectedIndex = _lastIndex ;
  165. [self pushLoginViewController];
  166. }
  167. }
  168. }
  169. }
  170. /* 配置启动页 */
  171. - (void)setupAd {
  172. //设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
  173. [XHLaunchAd setLaunchSourceType:SourceTypeLaunchScreen];
  174. CGFloat width = HJHorizontalScale(180);
  175. CGFloat height = 42;
  176. UIButton *launchStartButton = [UIButton hj_createGradientButtonWithTitle:@"开启加薪之旅"];
  177. launchStartButton.titleLabel.font = [UIFont systemFontOfSize:HJHorizontalScale(16)];
  178. launchStartButton.frame = CGRectMake((SCREEN_WIDTH-width)/2, (SCREEN_HEIGHT-height-90), width, height);
  179. [launchStartButton addTarget:self action:@selector(launchStartButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  180. UILabel *launchVersionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (SCREEN_HEIGHT-45), SCREEN_WIDTH, 20)];
  181. launchVersionLabel.text = [NSString stringWithFormat:@"v%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
  182. launchVersionLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
  183. launchVersionLabel.font = [UIFont systemFontOfSize:11];
  184. launchVersionLabel.textAlignment = NSTextAlignmentCenter;
  185. XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration defaultConfiguration];
  186. imageAdconfiguration.duration = 1;
  187. imageAdconfiguration.subViews = @[launchVersionLabel, launchStartButton];
  188. imageAdconfiguration.skipButtonType = SkipTypeNone;
  189. imageAdconfiguration.showFinishAnimate = ShowFinishAnimateLite;
  190. [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
  191. }
  192. - (void)applicationWillResignActive:(UIApplication *)application {
  193. }
  194. - (void)applicationDidEnterBackground:(UIApplication *)application {
  195. }
  196. - (void)applicationWillEnterForeground:(UIApplication *)application {
  197. }
  198. - (void)applicationDidBecomeActive:(UIApplication *)application {
  199. }
  200. - (void)applicationWillTerminate:(UIApplication *)application {
  201. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  202. }
  203. @end