// // FirstLinkAppDelegate.m // FirstLink // // Created by mac on 14-8-25. // Copyright (c) 2014年 FirstLink. All rights reserved. // #import "FirstLinkAppDelegate.h" #import "FKGuideManager.h" #import "FKMessageManager.h" #import "FKRemoteConfigManager.h" #import "SchemaManager.h" #import "UserDefaultManager.h" #import "FKWindowViewManager.h" #import "OAuthManager.h" #import #import #import "FKLaunchAnimation.h" #import "FKLaunchRequest.h" #import "FKAppearanceUtil.h" #import "FKUMengUtil.h" #import "FKReachabilityUtil.h" #import "FKLogUtil.h" #import "FKTargetConfigUtil.h" #import #import "FKAddressDetailViewModel.h" #import "FLControllerHelper.h" #import "FKRecommendPageController.h" #import "NSString+MD5.h" #import "WebViewController.h" @interface FirstLinkAppDelegate () @end @implementation FirstLinkAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [IQKeyboardManager sharedManager].enable = TRUE; [IQKeyboardManager sharedManager].shouldShowTextFieldPlaceholder = FALSE; [FKAppearanceUtil configAppearance]; [FKUMengUtil configUMengPush:launchOptions delegate:self]; #ifndef DEBUG [FKUMengUtil configUMengAnalysis]; #endif [FKLogUtil configCocoaLumberjack]; [[FKReachabilityUtil sharedInstance] configReachability]; [FKMessageManager configHuanxinAppKey]; [[OAuthManager sharedManager].weiboAuth initWeiboSDK]; [[OAuthManager sharedManager].weixinAuth initWeixinSDK]; [[OAuthManager sharedManager].qqAuth initQQSDK]; [FKRemoteConfigManager asyncRequsetConfig]; [FKAddressDetailViewModel asyncRequestProvinceCity]; [[UserDefaultManager sharedManager] removeUserDefaultKey:LAST_ACTIVITY_URL_KEY]; [self.window makeKeyAndVisible]; [FKAppearanceUtil configTabBarController]; [FKLaunchRequest requestOperationAlertInfo]; // 显示自定义动画,必须在window显示之后添加 [self showLaunchAnimation]; return YES; } - (void)showLaunchAnimation { FKLaunchAnimation *view = [[FKLaunchAnimation alloc] initWithFrame:self.window.bounds]; [self.window addSubview:view]; [view startAnimation:^(BOOL finished, NSString *targetURL) { if ([targetURL isKindOfClass:[NSString class]] && targetURL.length > 0) { [[SchemaManager sharedManager] parserURL:[NSURL URLWithString:targetURL] shouldCache:YES]; } if ([FKGuideManager isNeedShowGuideController]) { [FKGuideManager showGuideController]; } else { [[FKWindowViewManager sharedManager] showFloatView:nil]; } [view removeFromSuperview]; }]; } #pragma mark - Notification -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken { DDLogDebug(@"%@", deviceToken); // 向fine服务器注册token,token会与用户关联 NSString *stringToken = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; NSString *noEmptyToken = [stringToken stringByReplacingOccurrencesOfString:@" " withString:@""]; [[UserDefaultManager sharedManager] setUserDefaultObject:noEmptyToken key:REMOTE_NOTIFICATION_TOKEN]; [SystemUtil asyncUploadRemotePushToken:noEmptyToken]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [[EMClient sharedClient] bindDeviceToken:deviceToken]; }); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [UMessage didReceiveRemoteNotification:userInfo]; } -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{ NSDictionary * userInfo = notification.request.content.userInfo; if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { //应用处于前台时的远程推送接受 //必须加这句代码 // [UMessage didReceiveRemoteNotification:userInfo]; if ([userInfo.allKeys containsObject:@"custom"]) { [[FKMessageManager sharedInstance] refreshMessageUnreadMessage]; } } else { //应用处于前台时的本地推送接受 } } //iOS10新增:处理后台点击通知的代理方法 -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{ NSDictionary * userInfo = response.notification.request.content.userInfo; if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { //应用处于后台时的远程推送接受 //必须加这句代码 [UMessage didReceiveRemoteNotification:userInfo]; if ([userInfo objectForKey:@"url"]) { NSURL *url = [NSURL URLWithString: userInfo[@"url"]]; if ([url.host isEqualToString:PostHost]) { [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPagePushMessage values:nil]; } [[SchemaManager sharedManager] parserURL:url shouldCache:YES]; } } else { //应用处于后台时的本地推送接受 } } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { if (application.applicationState == UIApplicationStateActive) { if ([userInfo.allKeys containsObject:@"custom"]) { [[FKMessageManager sharedInstance] refreshMessageUnreadMessage]; } } else { if ([userInfo objectForKey:@"url"]) { NSURL *url = [NSURL URLWithString: userInfo[@"url"]]; if ([url.host isEqualToString:PostHost]) { [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPagePushMessage values:nil]; } [[SchemaManager sharedManager] parserURL:url shouldCache:YES]; } } } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { NSDictionary *userInfo = notification.userInfo; if ([userInfo objectForKey:@"url"]) { [[SchemaManager sharedManager] parserURL:[NSURL URLWithString: userInfo[@"url"]] shouldCache:YES]; } } #pragma mark - Life Cycle - (void)applicationDidEnterBackground:(UIApplication *)application { // 让SDK得到App目前的各种状态,以便让SDK做出对应当前场景的操作 [[EMClient sharedClient] applicationDidEnterBackground:application]; [[SchemaManager sharedManager] clearURL]; } - (void)applicationWillEnterForeground:(UIApplication *)application { // 让SDK得到App目前的各种状态,以便让SDK做出对应当前场景的操作 [[EMClient sharedClient] applicationWillEnterForeground:application]; } - (void)applicationDidBecomeActive:(UIApplication *)application { [[FKServerUtil sharedInstance] resetServerToDomain]; [FKLaunchRequest requestLaunchUpdateWithInterval:3]; [SystemUtil asyncUploadDeviceInfo]; [SystemUtil asyncRequestUserAuthority]; // [FKLogUtil asyncUploadRollingFiles]; [RegisterViewModel asyncUserWithServer]; // 管家的角标提醒优化后删除无用Notification [FKMessageManager checkThenLoginChat:^{}]; [[FKMessageManager sharedInstance] refreshMessageUnreadMessage]; [[NSNotificationCenter defaultCenter] postNotificationName:APPLICATION_DIDFINISHLAUNCHING object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:HUANXIN_LOGIN_SUCCESS object:nil]; } - (void)applicationWillTerminate:(UIApplication *)application { // 让SDK得到App目前的各种状态,以便让SDK做出对应当前场景的操作 [WebViewController removeWebCache]; } #pragma mark - URL Wake -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { //如果涉及其他应用交互,请做如下判断,例如:还可能和新浪微博进行交互 if ([url.scheme isEqualToString:@"firstlinkapp"]) { [[SchemaManager sharedManager] parserURL:url shouldCache:YES]; return YES; } else if ([url.scheme isEqualToString:[FKTargetConfigUtil weixinAppKey]]) { if ([url.host isEqualToString:@"pay"]){ return [WXApi handleOpenURL:url delegate:self]; } if ([OAuthManager sharedManager].delegate) { return [WXApi handleOpenURL:url delegate:[OAuthManager sharedManager].delegate]; } else { // 微信分享回调 return [WXApi handleOpenURL:url delegate:[OAuthManager sharedManager].shareResCall]; } } else if ([url.scheme isEqualToString:@"wb4030920748"]) { return [WeiboSDK handleOpenURL:url delegate:[OAuthManager sharedManager].delegate]; } else if ([url.scheme isEqualToString:@"tencent1104752138"]) { return [TencentOAuth HandleOpenURL:url] || [QQApiInterface handleOpenURL:url delegate:[OAuthManager sharedManager].shareResCall]; } else if ([url.scheme isEqualToString:@"alipay2088612219594476"] || [url.scheme isEqualToString:@"alipay2088521575254123"]){ [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) { // 无论是否有安装支付宝客户端,如果用户取消付款,都会调到这里来 // 如果安装了支付宝客户端,会在delegate先执行(但不做callBack),然后再到这,如果是web支付,取消的时候直接调这里来(因为是push一个web页面) if ([resultDic[@"resultStatus"] integerValue] == 9000){ // 付款成功 [[NSNotificationCenter defaultCenter] postNotificationName:AlipaySuccessNotificaitonName object:nil]; } else { // 付款失败 [[NSNotificationCenter defaultCenter] postNotificationName:AlipayFailedNotificaitonName object:resultDic]; } }]; } return YES; } #pragma mark - Weixin -(void)onResp:(BaseResp *)resp { if ([resp isKindOfClass:[PayResp class]]) { if (resp.errCode == 0) { // 支付成功 [[NSNotificationCenter defaultCenter] postNotificationName:WeixinPaySuccessNotificaitonName object:nil]; } return; } } #pragma mark - Spotlight - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler { NSDictionary *userInfo = userActivity.userInfo; NSString *urlString = userInfo[CSSearchableItemActivityIdentifier]; NSURL *url = [NSURL URLWithString:urlString]; if ([url.scheme isEqualToString:@"firstlinkapp"]) { [[SchemaManager sharedManager] parserURL:url shouldCache:YES]; return YES; } return YES; } @end