| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- //
- // AppDelegate.m
- // HappyJob
- //
- // Created by Bob on 2019/3/11.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "AppDelegate.h"
- #import <WXApi.h>
- #import <Bugly/Bugly.h>
- #import <AlipaySDK/AlipaySDK.h>
- #import <XHLaunchAd/XHLaunchAd.h>
- #import <IQKeyboardManager/IQKeyboardManager.h>
- #import <AMapFoundationKit/AMapFoundationKit.h>
- #import "HJLoginPhoneViewController.h"//登录
- #import "HJMainViewController.h"//C端的
- #import "BMainViewController.h"//自发布的
- #import "HJWelcomeViewController.h"//引导页
- #import "BReleaseJobsViewController.h"//发布工作
- #import "BReleaseSelectTypeView.h"//选择发布类型
- #import "FBNetworkingConfig.h"//网络配置
- #import "HJWeiXinAPIManager.h"
- #import "HJUserInfoModel.h"
- #import "UIButton+HJGradientButton.h"
- @interface AppDelegate () <HJWelcomeViewDelegate,UITabBarControllerDelegate>
- @property (nonatomic, strong) BMainViewController *bTabBarC;//自发布
- @property (nonatomic, strong) HJMainViewController *CTabBarC;//C端
- @property (nonatomic, assign) int lastIndex;//tabBar选中的上一个的视图索引
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-
- //配置Bugly
- [Bugly startWithAppId:kBuglyAppID];
-
- [[HJAppUserType sharedInstance] loadUserType];
-
- [[HJAppUserType sharedInstance] setIslogin:@"0"];
- [[HJAppUserType sharedInstance] saveUserType];
- if ([[HJAppUserType sharedInstance].clearLogin intValue] == 0 )
- {
- [HJUserInfoModel clear];//清除登陆
- [[HJAppUserType sharedInstance] setClearLogin:@"1"];
- [[HJAppUserType sharedInstance] saveUserType];
- }
-
- //设置状态栏为白色的
- // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
-
- //配置广告数据
- [self setupAd];
-
- // 高德地图
- [AMapServices sharedServices].apiKey = kGAODEAPIKey;
-
- // 微信授权
- [WXApi registerApp:kWeiXinAPIKey universalLink:kuniversalLink];
-
- // 配置接口调用
- [FBNetworkingConfig sharedConfig].baseURL = kHJBaseURL;
-
- // DDTTYLogger,你的日志语句将被发送到Xcode控制台
- [DDLog addLogger:[DDTTYLogger sharedInstance]];
-
- // 设置键盘监听管理
- IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];
- keyboardManager.toolbarDoneBarButtonItemText = @"完成";
- keyboardManager.shouldResignOnTouchOutside = YES;
-
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- self.window.backgroundColor = [UIColor whiteColor];
-
- //引导页
- HJWelcomeViewController *welcomeViewController = [[HJWelcomeViewController alloc] init];
- welcomeViewController.delegate = self;
- if (welcomeViewController.isShow)
- {
- self.window.rootViewController = welcomeViewController;
- }
- else
- {
- self.window.rootViewController = [self setupFirstViewController];
- }
-
- [self.window makeKeyAndVisible];
-
- return YES;
- }
- /* iOS 9 之前用 */
- - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
-
- [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
- [self AlipayPayResult:url];
- return YES;
- }
- - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
-
- [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
- [self AlipayPayResult:url];
-
- return YES;
- }
- /* iOS 9之后用 */
- - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
-
- [WXApi handleOpenURL:url delegate:[HJWeiXinAPIManager sharedManager]];
- [self AlipayPayResult:url];
-
- return YES;
- }
- #pragma mark - HJWelcomeViewDelegate
- - (void)skipWelcomeView:(HJWelcomeViewController *)welcomeView {
-
- self.window.rootViewController = [self setupFirstViewController];
- }
- #pragma mark - UITabBarControllerDelegate 代理
- - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
- {
- if (tabBarController == _bTabBarC)
- {
- if (_bTabBarC.tabBar.selectedItem.tag == 2 && [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 0)
- {//取消tabBar的点击事件
- return NO;
- }
- else
- {
- _lastIndex = (int)tabBarController.selectedIndex;
- return YES;
- }
- }
- else
- {
- _lastIndex = (int)tabBarController.selectedIndex;
- return YES;
- }
- }
- - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
- {
- if (tabBarController == _bTabBarC)
- {//自发布
- if (tabBarController.selectedIndex == 2)
- {
- if ([[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 3 || [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 2 || [[HJCompanyInfoModel companyInfo].authenticationStatus integerValue] == 1)
- {
- tabBarController.selectedIndex = _lastIndex ;
- BReleaseSelectTypeView *view = [[BReleaseSelectTypeView alloc]init];
- view.positionCategoryBlock = ^(NSInteger category) {
-
- BReleaseJobsViewController *certification=[[BReleaseJobsViewController alloc]init];
- certification.positionType = category;
- UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:certification];
- navi.modalPresentationStyle = UIModalPresentationFullScreen;
- [self.window.rootViewController presentViewController:navi animated:YES completion:nil];
- };
- [[[[UIApplication sharedApplication] delegate] window] addSubview:view];
- }
- else
- {
- tabBarController.selectedIndex = _lastIndex ;
- }
- }
- }
- else
- {
- if ([HJMemberInfoModel memberInfo].memberId == nil || [[HJMemberInfoModel memberInfo].memberId isEqualToString: @""])
- {
- if( tabBarController.selectedIndex == 2 || tabBarController.selectedIndex == 3)
- {
- tabBarController.selectedIndex = _lastIndex ;
- [self pushLoginViewController];
- }
- }
- }
- }
- #pragma mark - private methods
- /* 设置展示哪个端(C端和自发布端) */
- - (UIViewController *)setupFirstViewController {
-
- if ([HJMemberInfoModel memberInfo].memberId == nil || [[HJMemberInfoModel memberInfo].memberId isEqualToString: @""])
- { //c端
- _CTabBarC = [[HJMainViewController alloc] init];
- _CTabBarC.delegate = self;
- return _CTabBarC;
- }
- else
- {
- if (USERTYPE)
- { //自发布
- _bTabBarC = [[BMainViewController alloc]init];
- _bTabBarC.delegate = self;
- return _bTabBarC;
- }
- else
- { //c端
- _CTabBarC = [[HJMainViewController alloc] init];
- _CTabBarC.delegate = self;
- return _CTabBarC;
- }
- }
- }
- /* 推出登录 */
- -(void)pushLoginViewController {
-
- HJLoginPhoneViewController *loginVC=[[HJLoginPhoneViewController alloc]init];
- UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:loginVC];
- navi.modalPresentationStyle = UIModalPresentationFullScreen;
- [self.window.rootViewController presentViewController:navi animated:YES completion:nil];
- }
- /* 切换身份 */
- - (void)switchTabBar {
-
- self.window.rootViewController = [self setupFirstViewController];
- }
- /* 配置启动页 */
- - (void)setupAd {
-
- //设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
- [XHLaunchAd setLaunchSourceType:SourceTypeLaunchScreen];
- UILabel *launchVersionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (SCREEN_HEIGHT-45), SCREEN_WIDTH, 20)];
- launchVersionLabel.text = [NSString stringWithFormat:@"v%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
- launchVersionLabel.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
- launchVersionLabel.font = [UIFont systemFontOfSize:11];
- launchVersionLabel.textAlignment = NSTextAlignmentCenter;
-
- XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration defaultConfiguration];
- imageAdconfiguration.duration = 1;
- imageAdconfiguration.subViews = @[launchVersionLabel];
- imageAdconfiguration.skipButtonType = SkipTypeNone;
- imageAdconfiguration.showFinishAnimate = ShowFinishAnimateLite;
- [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
- }
- /* 支付宝支付结果 */
- - (void)AlipayPayResult:(NSURL *)url {
-
- //跳转支付宝钱包进行支付,处理支付结果
- [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
-
- if([resultDic[@"resultStatus"] intValue] == 9000)
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiAliPaySucceed object:nil];
- }
- else if([resultDic[@"resultStatus"] intValue] == 6001)
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiAliPayCancel object:nil];
- }
- else
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:kNotifiAliPayFailed object:nil];
- }
-
- }];
- }
- - (void)applicationWillResignActive:(UIApplication *)application {
-
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application {
-
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application {
-
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application {
-
- }
- - (void)applicationWillTerminate:(UIApplication *)application {
-
- }
- @end
|