Няма описание

FirstLinkAppDelegate.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. //
  2. // FirstLinkAppDelegate.m
  3. // FirstLink
  4. //
  5. // Created by mac on 14-8-25.
  6. // Copyright (c) 2014年 FirstLink. All rights reserved.
  7. //
  8. #import "FirstLinkAppDelegate.h"
  9. #import "FKGuideManager.h"
  10. #import "FKMessageManager.h"
  11. #import "FKRemoteConfigManager.h"
  12. #import "SchemaManager.h"
  13. #import "UserDefaultManager.h"
  14. #import "FKWindowViewManager.h"
  15. #import "OAuthManager.h"
  16. #import <AlipaySDK/AlipaySDK.h>
  17. #import <IQKeyboardManager/IQKeyboardManager.h>
  18. #import "FKLaunchAnimation.h"
  19. #import "FKLaunchRequest.h"
  20. #import "FKAppearanceUtil.h"
  21. #import "FKUMengUtil.h"
  22. #import "FKReachabilityUtil.h"
  23. #import "FKLogUtil.h"
  24. #import "FKTargetConfigUtil.h"
  25. #import <CoreSpotlight/CoreSpotlight.h>
  26. #import "FKAddressDetailViewModel.h"
  27. #import "FLControllerHelper.h"
  28. #import "FKRecommendPageController.h"
  29. #import "NSString+MD5.h"
  30. #import "WebViewController.h"
  31. @interface FirstLinkAppDelegate ()
  32. <WXApiDelegate, UNUserNotificationCenterDelegate>
  33. @end
  34. @implementation FirstLinkAppDelegate
  35. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  36. // Override point for customization after application launch.
  37. [IQKeyboardManager sharedManager].enable = TRUE;
  38. [IQKeyboardManager sharedManager].shouldShowTextFieldPlaceholder = FALSE;
  39. [FKAppearanceUtil configAppearance];
  40. [FKUMengUtil configUMengPush:launchOptions delegate:self];
  41. #ifndef DEBUG
  42. [FKUMengUtil configUMengAnalysis];
  43. #endif
  44. [FKLogUtil configCocoaLumberjack];
  45. [[FKReachabilityUtil sharedInstance] configReachability];
  46. [FKMessageManager configHuanxinAppKey];
  47. [[OAuthManager sharedManager].weiboAuth initWeiboSDK];
  48. [[OAuthManager sharedManager].weixinAuth initWeixinSDK];
  49. [[OAuthManager sharedManager].qqAuth initQQSDK];
  50. [FKRemoteConfigManager asyncRequsetConfig];
  51. [FKAddressDetailViewModel asyncRequestProvinceCity];
  52. [[UserDefaultManager sharedManager] removeUserDefaultKey:LAST_ACTIVITY_URL_KEY];
  53. [self.window makeKeyAndVisible];
  54. [FKAppearanceUtil configTabBarController];
  55. [FKLaunchRequest requestOperationAlertInfo];
  56. // 显示自定义动画,必须在window显示之后添加
  57. [self showLaunchAnimation];
  58. return YES;
  59. }
  60. - (void)showLaunchAnimation {
  61. FKLaunchAnimation *view = [[FKLaunchAnimation alloc] initWithFrame:self.window.bounds];
  62. [self.window addSubview:view];
  63. [view startAnimation:^(BOOL finished, NSString *targetURL) {
  64. if ([targetURL isKindOfClass:[NSString class]] && targetURL.length > 0) {
  65. [[SchemaManager sharedManager] parserURL:[NSURL URLWithString:targetURL] shouldCache:YES];
  66. }
  67. if ([FKGuideManager isNeedShowGuideController]) {
  68. [FKGuideManager showGuideController];
  69. } else {
  70. [[FKWindowViewManager sharedManager] showFloatView:nil];
  71. }
  72. [view removeFromSuperview];
  73. }];
  74. }
  75. #pragma mark - Notification
  76. -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken {
  77. DDLogDebug(@"%@", deviceToken);
  78. // 向fine服务器注册token,token会与用户关联
  79. NSString *stringToken = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
  80. NSString *noEmptyToken = [stringToken stringByReplacingOccurrencesOfString:@" " withString:@""];
  81. [[UserDefaultManager sharedManager] setUserDefaultObject:noEmptyToken key:REMOTE_NOTIFICATION_TOKEN];
  82. [SystemUtil asyncUploadRemotePushToken:noEmptyToken];
  83. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  84. [[EMClient sharedClient] bindDeviceToken:deviceToken];
  85. });
  86. }
  87. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  88. [UMessage didReceiveRemoteNotification:userInfo];
  89. }
  90. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
  91. NSDictionary * userInfo = notification.request.content.userInfo;
  92. if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  93. //应用处于前台时的远程推送接受
  94. //必须加这句代码
  95. // [UMessage didReceiveRemoteNotification:userInfo];
  96. if ([userInfo.allKeys containsObject:@"custom"]) {
  97. [[FKMessageManager sharedInstance] refreshMessageUnreadMessage];
  98. }
  99. } else {
  100. //应用处于前台时的本地推送接受
  101. }
  102. }
  103. //iOS10新增:处理后台点击通知的代理方法
  104. -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
  105. NSDictionary * userInfo = response.notification.request.content.userInfo;
  106. if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  107. //应用处于后台时的远程推送接受
  108. //必须加这句代码
  109. [UMessage didReceiveRemoteNotification:userInfo];
  110. if ([userInfo objectForKey:@"url"]) {
  111. NSURL *url = [NSURL URLWithString: userInfo[@"url"]];
  112. if ([url.host isEqualToString:PostHost]) {
  113. [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPagePushMessage values:nil];
  114. }
  115. [[SchemaManager sharedManager] parserURL:url shouldCache:YES];
  116. }
  117. } else {
  118. //应用处于后台时的本地推送接受
  119. }
  120. }
  121. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  122. if (application.applicationState == UIApplicationStateActive) {
  123. if ([userInfo.allKeys containsObject:@"custom"]) {
  124. [[FKMessageManager sharedInstance] refreshMessageUnreadMessage];
  125. }
  126. } else {
  127. if ([userInfo objectForKey:@"url"]) {
  128. NSURL *url = [NSURL URLWithString: userInfo[@"url"]];
  129. if ([url.host isEqualToString:PostHost]) {
  130. [[FKPageRouterUtil sharedInstance] pushPageRefer:PRPagePushMessage values:nil];
  131. }
  132. [[SchemaManager sharedManager] parserURL:url shouldCache:YES];
  133. }
  134. }
  135. }
  136. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  137. NSDictionary *userInfo = notification.userInfo;
  138. if ([userInfo objectForKey:@"url"]) {
  139. [[SchemaManager sharedManager] parserURL:[NSURL URLWithString: userInfo[@"url"]] shouldCache:YES];
  140. }
  141. }
  142. #pragma mark - Life Cycle
  143. - (void)applicationDidEnterBackground:(UIApplication *)application {
  144. // 让SDK得到App目前的各种状态,以便让SDK做出对应当前场景的操作
  145. [[EMClient sharedClient] applicationDidEnterBackground:application];
  146. [[SchemaManager sharedManager] clearURL];
  147. }
  148. - (void)applicationWillEnterForeground:(UIApplication *)application {
  149. // 让SDK得到App目前的各种状态,以便让SDK做出对应当前场景的操作
  150. [[EMClient sharedClient] applicationWillEnterForeground:application];
  151. }
  152. - (void)applicationDidBecomeActive:(UIApplication *)application {
  153. [[FKServerUtil sharedInstance] resetServerToDomain];
  154. [FKLaunchRequest requestLaunchUpdateWithInterval:3];
  155. [SystemUtil asyncUploadDeviceInfo];
  156. [SystemUtil asyncRequestUserAuthority];
  157. // [FKLogUtil asyncUploadRollingFiles];
  158. [RegisterViewModel asyncUserWithServer];
  159. // 管家的角标提醒优化后删除无用Notification
  160. [FKMessageManager checkThenLoginChat:^{}];
  161. [[FKMessageManager sharedInstance] refreshMessageUnreadMessage];
  162. [[NSNotificationCenter defaultCenter] postNotificationName:APPLICATION_DIDFINISHLAUNCHING
  163. object:nil];
  164. [[NSNotificationCenter defaultCenter] postNotificationName:HUANXIN_LOGIN_SUCCESS
  165. object:nil];
  166. }
  167. - (void)applicationWillTerminate:(UIApplication *)application {
  168. // 让SDK得到App目前的各种状态,以便让SDK做出对应当前场景的操作
  169. [WebViewController removeWebCache];
  170. }
  171. #pragma mark - URL Wake
  172. -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  173. //如果涉及其他应用交互,请做如下判断,例如:还可能和新浪微博进行交互
  174. if ([url.scheme isEqualToString:@"firstlinkapp"]) {
  175. [[SchemaManager sharedManager] parserURL:url shouldCache:YES];
  176. return YES;
  177. } else if ([url.scheme isEqualToString:[FKTargetConfigUtil weixinAppKey]]) {
  178. if ([url.host isEqualToString:@"pay"]){
  179. return [WXApi handleOpenURL:url delegate:self];
  180. }
  181. if ([OAuthManager sharedManager].delegate) {
  182. return [WXApi handleOpenURL:url delegate:[OAuthManager sharedManager].delegate];
  183. } else {
  184. // 微信分享回调
  185. return [WXApi handleOpenURL:url delegate:[OAuthManager sharedManager].shareResCall];
  186. }
  187. } else if ([url.scheme isEqualToString:@"wb4030920748"]) {
  188. return [WeiboSDK handleOpenURL:url delegate:[OAuthManager sharedManager].delegate];
  189. } else if ([url.scheme isEqualToString:@"tencent1104752138"]) {
  190. return [TencentOAuth HandleOpenURL:url] || [QQApiInterface handleOpenURL:url delegate:[OAuthManager sharedManager].shareResCall];
  191. } else if ([url.scheme isEqualToString:@"alipay2088612219594476"]
  192. || [url.scheme isEqualToString:@"alipay2088521575254123"]){
  193. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  194. // 无论是否有安装支付宝客户端,如果用户取消付款,都会调到这里来
  195. // 如果安装了支付宝客户端,会在delegate先执行(但不做callBack),然后再到这,如果是web支付,取消的时候直接调这里来(因为是push一个web页面)
  196. if ([resultDic[@"resultStatus"] integerValue] == 9000){
  197. // 付款成功
  198. [[NSNotificationCenter defaultCenter] postNotificationName:AlipaySuccessNotificaitonName object:nil];
  199. } else {
  200. // 付款失败
  201. [[NSNotificationCenter defaultCenter] postNotificationName:AlipayFailedNotificaitonName object:resultDic];
  202. }
  203. }];
  204. }
  205. return YES;
  206. }
  207. #pragma mark - Weixin
  208. -(void)onResp:(BaseResp *)resp {
  209. if ([resp isKindOfClass:[PayResp class]]) {
  210. if (resp.errCode == 0) {
  211. // 支付成功
  212. [[NSNotificationCenter defaultCenter] postNotificationName:WeixinPaySuccessNotificaitonName object:nil];
  213. }
  214. return;
  215. }
  216. }
  217. #pragma mark - Spotlight
  218. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
  219. NSDictionary *userInfo = userActivity.userInfo;
  220. NSString *urlString = userInfo[CSSearchableItemActivityIdentifier];
  221. NSURL *url = [NSURL URLWithString:urlString];
  222. if ([url.scheme isEqualToString:@"firstlinkapp"]) {
  223. [[SchemaManager sharedManager] parserURL:url shouldCache:YES];
  224. return YES;
  225. }
  226. return YES;
  227. }
  228. @end