AppDelegate.m 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 <WXApi.h>
  10. #import <Bugly/Bugly.h>
  11. #import <AlipaySDK/AlipaySDK.h>
  12. #import <XHLaunchAd/XHLaunchAd.h>
  13. #import <IQKeyboardManager/IQKeyboardManager.h>
  14. #import <AMapFoundationKit/AMapFoundationKit.h>
  15. #import "HJLoginPhoneViewController.h"//登录
  16. #import "HJMainViewController.h"//C端的
  17. #import "BMainViewController.h"//自发布的
  18. #import "HJWelcomeViewController.h"//引导页
  19. #import "BReleaseJobsViewController.h"//发布工作
  20. #import "BReleaseSelectTypeView.h"//选择发布类型
  21. #import "FBNetworkingConfig.h"//网络配置
  22. #import "HJWeiXinAPIManager.h"
  23. #import "HJUserInfoModel.h"
  24. #import "UIButton+HJGradientButton.h"
  25. @interface AppDelegate () <HJWelcomeViewDelegate,UITabBarControllerDelegate>
  26. @property (nonatomic, strong) BMainViewController *bTabBarC;//自发布
  27. @property (nonatomic, strong) HJMainViewController *CTabBarC;//C端
  28. @property (nonatomic, assign) int lastIndex;//tabBar选中的上一个的视图索引
  29. @end
  30. @implementation AppDelegate
  31. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  32. //配置Bugly
  33. [Bugly startWithAppId:kBuglyAppID];
  34. [[HJAppUserType sharedInstance] loadUserType];
  35. [[HJAppUserType sharedInstance] setIslogin:@"0"];
  36. [[HJAppUserType sharedInstance] saveUserType];
  37. if ([[HJAppUserType sharedInstance].clearLogin intValue] == 0 )
  38. {
  39. [HJUserInfoModel clear];//清除登陆
  40. [[HJAppUserType sharedInstance] setClearLogin:@"1"];
  41. [[HJAppUserType sharedInstance] saveUserType];
  42. }
  43. //设置状态栏为白色的
  44. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
  45. //配置广告数据
  46. [self setupAd];
  47. // 高德地图
  48. [AMapServices sharedServices].apiKey = kGAODEAPIKey;
  49. // 微信授权
  50. [WXApi registerApp:kWeiXinAPIKey universalLink:kuniversalLink];
  51. // 配置接口调用
  52. [FBNetworkingConfig sharedConfig].baseURL = kHJBaseURL;
  53. // DDTTYLogger,你的日志语句将被发送到Xcode控制台
  54. [DDLog addLogger:[DDTTYLogger sharedInstance]];
  55. // 设置键盘监听管理
  56. IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
  57. keyboardManager.toolbarDoneBarButtonItemText = @"完成";
  58. keyboardManager.shouldResignOnTouchOutside = YES;
  59. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  60. self.window.backgroundColor = [UIColor whiteColor];
  61. //引导页
  62. HJWelcomeViewController *welcomeViewController = [[HJWelcomeViewController alloc] init];
  63. welcomeViewController.delegate = self;
  64. if (welcomeViewController.isShow)
  65. {
  66. self.window.rootViewController = welcomeViewController;
  67. }
  68. else
  69. {
  70. self.window.rootViewController = [self setupFirstViewController];
  71. }
  72. [self.window makeKeyAndVisible];
  73. return YES;
  74. }
  75. /* iOS 9 之前用 */
  76. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
  77. [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
  78. [self AlipayPayResult:url];
  79. return YES;
  80. }
  81. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  82. [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
  83. [self AlipayPayResult:url];
  84. return YES;
  85. }
  86. /* iOS 9之后用 */
  87. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  88. [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
  89. [self AlipayPayResult:url];
  90. return YES;
  91. }
  92. #pragma mark - HJWelcomeViewDelegate
  93. - (void)skipWelcomeView:(HJWelcomeViewController *)welcomeView {
  94. self.window.rootViewController = [self setupFirstViewController];
  95. }
  96. #pragma mark - UITabBarControllerDelegate 代理
  97. - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
  98. {
  99. if (tabBarController == _bTabBarC)
  100. {
  101. if (_bTabBarC.tabBar.selectedItem.tag == 2 && [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 0)
  102. {//取消tabBar的点击事件
  103. return NO;
  104. }
  105. else
  106. {
  107. _lastIndex = (int)tabBarController.selectedIndex;
  108. return YES;
  109. }
  110. }
  111. else
  112. {
  113. _lastIndex = (int)tabBarController.selectedIndex;
  114. return YES;
  115. }
  116. }
  117. - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
  118. {
  119. if (tabBarController == _bTabBarC)
  120. {//自发布
  121. if (tabBarController.selectedIndex == 2)
  122. {
  123. if ([[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 3 || [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 2 || [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 1)
  124. {
  125. tabBarController.selectedIndex = _lastIndex ;
  126. BReleaseSelectTypeView *view = [[BReleaseSelectTypeView alloc]init];
  127. view.positionCategoryBlock = ^(NSInteger category) {
  128. BReleaseJobsViewController *certification=[[BReleaseJobsViewController alloc]init];
  129. certification.positionType = category;
  130. UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:certification];
  131. navi.modalPresentationStyle = UIModalPresentationFullScreen;
  132. [self.window.rootViewController presentViewController:navi animated:YES completion:nil];
  133. };
  134. [[[[UIApplication sharedApplication] delegate] window] addSubview:view];
  135. }
  136. else
  137. {
  138. tabBarController.selectedIndex = _lastIndex ;
  139. }
  140. }
  141. }
  142. else
  143. {
  144. if ([HJMemberInfoModel memberInfo].memberId == nil || [[HJMemberInfoModel memberInfo].memberId isEqualToString: @""])
  145. {
  146. if( tabBarController.selectedIndex == 2 || tabBarController.selectedIndex == 3)
  147. {
  148. tabBarController.selectedIndex = _lastIndex ;
  149. [self pushLoginViewController];
  150. }
  151. }
  152. }
  153. }
  154. #pragma mark - private methods
  155. /* 设置展示哪个端(C端和自发布端) */
  156. - (UIViewController *)setupFirstViewController {
  157. if ([HJMemberInfoModel memberInfo].memberId == nil || [[HJMemberInfoModel memberInfo].memberId isEqualToString: @""])
  158. { //c端
  159. _CTabBarC = [[HJMainViewController alloc] init];
  160. _CTabBarC.delegate = self;
  161. return _CTabBarC;
  162. }
  163. else
  164. {
  165. if (USERTYPE)
  166. { //自发布
  167. _bTabBarC = [[BMainViewController alloc]init];
  168. _bTabBarC.delegate = self;
  169. return _bTabBarC;
  170. }
  171. else
  172. { //c端
  173. _CTabBarC = [[HJMainViewController alloc] init];
  174. _CTabBarC.delegate = self;
  175. return _CTabBarC;
  176. }
  177. }
  178. }
  179. /* 推出登录 */
  180. -(void)pushLoginViewController {
  181. HJLoginPhoneViewController *loginVC=[[HJLoginPhoneViewController alloc]init];
  182. UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:loginVC];
  183. navi.modalPresentationStyle = UIModalPresentationFullScreen;
  184. [self.window.rootViewController presentViewController:navi animated:YES completion:nil];
  185. }
  186. /* 切换身份 */
  187. - (void)switchTabBar {
  188. self.window.rootViewController = [self setupFirstViewController];
  189. }
  190. /* 配置启动页 */
  191. - (void)setupAd {
  192. //设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
  193. [XHLaunchAd setLaunchSourceType:SourceTypeLaunchScreen];
  194. UILabel *launchVersionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (SCREEN_HEIGHT-45), SCREEN_WIDTH, 20)];
  195. launchVersionLabel.text = [NSString stringWithFormat:@"v%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
  196. launchVersionLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
  197. launchVersionLabel.font = [UIFont systemFontOfSize:11];
  198. launchVersionLabel.textAlignment = NSTextAlignmentCenter;
  199. XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration defaultConfiguration];
  200. imageAdconfiguration.duration = 1;
  201. imageAdconfiguration.subViews = @[launchVersionLabel];
  202. imageAdconfiguration.skipButtonType = SkipTypeNone;
  203. imageAdconfiguration.showFinishAnimate = ShowFinishAnimateLite;
  204. [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
  205. }
  206. /* 支付宝支付结果 */
  207. - (void)AlipayPayResult:(NSURL *)url {
  208. //跳转支付宝钱包进行支付,处理支付结果
  209. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  210. if([resultDic[@"resultStatus"] intValue] == 9000)
  211. {
  212. [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiAliPaySucceed object:nil];
  213. }
  214. else if([resultDic[@"resultStatus"] intValue] == 6001)
  215. {
  216. [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiAliPayCancel object:nil];
  217. }
  218. else
  219. {
  220. [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiAliPayFailed object:nil];
  221. }
  222. }];
  223. }
  224. - (void)applicationWillResignActive:(UIApplication *)application {
  225. }
  226. - (void)applicationDidEnterBackground:(UIApplication *)application {
  227. }
  228. - (void)applicationWillEnterForeground:(UIApplication *)application {
  229. }
  230. - (void)applicationDidBecomeActive:(UIApplication *)application {
  231. }
  232. - (void)applicationWillTerminate:(UIApplication *)application {
  233. }
  234. @end