AppDelegate.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. //
  2. // AppDelegate.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/9/14.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "NotBackUpiCloud.h" //设置禁止云同步
  10. #import "UncaughtExceptionHandler.h" //初始化程序异常
  11. #import "NewConfigureRootController.h" //控制类初始化
  12. #import "NewKeyboardManager.h" //键盘适配
  13. //#import "WXSDKHelper.h" //微信支付
  14. #import "JPushHelper.h" //极光推送
  15. #import "HuanXinHelper.h" //环信聊天
  16. #import "NewInterfaceReplacement.h" //当Token失效时 让用户选择强制退出
  17. #import "UIWindow+PazLabs.h"
  18. @interface AppDelegate ()<EMContactManagerDelegate>{
  19. UIAlertView *alertViewLog;//强制退出弹窗
  20. }
  21. @end
  22. @implementation AppDelegate
  23. + (AppDelegate *) shareDelegate
  24. {
  25. return (AppDelegate*)[[UIApplication sharedApplication] delegate];
  26. }
  27. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  28. // Override point for customization after application launch.
  29. /**
  30. * 配置公共通知对象
  31. */
  32. [self JiTaoServerPublicNotification];
  33. /**
  34. * 禁止上传icloud
  35. */
  36. [[NotBackUpiCloud sharedInstance] addNotBackUpiCloud];
  37. /**
  38. * 初始化异常 捕捉程序崩溃原因 弹窗提示
  39. */
  40. InstallUncaughtExceptionHandler();
  41. /**
  42. * 观察网络状态
  43. */
  44. [NetworkRequestManager observeNetworkStatus];
  45. /**
  46. * 配置微信SDK
  47. */
  48. // [[WXSDKHelper sharedInstance] setWXSDK];
  49. /**
  50. * 初始化极光推送
  51. */
  52. [[JPushHelper sharedInstance]setJPushAPNSSDK:application options:launchOptions];
  53. //获取系统的版本号
  54. NSString *currVersion = [NSString getMyApplicationVersion];
  55. //程序第一次启动时 会把版本号存到内存里 下次进来的时候进行版本号匹配
  56. //匹配成功则直接进入项目首页 否则默认进入项目介绍轮播页
  57. NSString *oldVersion = [NewUtils userDefaultsStringKey:NewAPPVersion];
  58. if (oldVersion.length > 0 && [oldVersion isEqualToString:currVersion]) {
  59. NSString *account = [NewUtils userDefaultsStringKey:NewAccountNumber];
  60. NSString *password = [NewUtils userDefaultsStringKey:NewAccountPassword];
  61. if (account.length==0 || password.length==0) {
  62. }else{
  63. /**
  64. * 环信自动登录
  65. */
  66. // [[HuanXinHelper sharedInstance]setHuanXinSDK:application options:launchOptions];
  67. /**
  68. * 技淘自动登录
  69. */
  70. [UserHelper automaticLogon];
  71. }
  72. }else{
  73. }
  74. /**
  75. * 设置根目录reWriteUserInfoFromLocation
  76. */
  77. [[NewConfigureRootController sharedInstance] setRootController];
  78. /**
  79. * 键盘适配
  80. */
  81. [[NewKeyboardManager sharedInstance] keyboardManager];
  82. return YES;
  83. }
  84. #pragma mark - 配置公共通知对象
  85. - (void)JiTaoServerPublicNotification
  86. {
  87. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotificationMethod:) name:NewJitaoServerPublicNotification object:nil];
  88. }
  89. #pragma mark - 公共通知 收到通知之后的处理
  90. - (void)receiveNotificationMethod:(NSNotification *)notication
  91. {
  92. // if ([notication.object isKindOfClass:[NSDictionary class]]){}
  93. if (notication.object) {
  94. NSLog(@"%@",notication.object);
  95. if ([notication.object[@"resource_id"] isEqualToString:@""]) {
  96. //为空的话 就往系统消息跳转
  97. //就跳转技淘智推
  98. [self Naughtytechnique:@"0"];
  99. return;
  100. }else{
  101. //就跳转技淘智推
  102. [self Naughtytechnique:@"1"];
  103. return;
  104. }
  105. }
  106. }
  107. - (void)Naughtytechnique:(NSString *)str{
  108. [[[self.window visibleViewController] navigationController] popToRootViewControllerAnimated:YES];
  109. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  110. [[NewBasicTabbarController sharedInstance] changeRootViewControllerEvent:0];
  111. [[NSNotificationCenter defaultCenter]postNotificationName:NewtuisongManageNotification object:str userInfo:nil];
  112. });
  113. }
  114. #pragma mark - 强制退出登录
  115. - (void)forceLogoutLogin
  116. {
  117. /*
  118. 登录失效 默认清除本地缓存~
  119. */
  120. //退出云信账号、解绑阿里云推送账号、删除用户单例类以及本地缓存保存的数据
  121. [UserHelper exitLogin];
  122. //退出环信账号
  123. [[HuanXinHelper sharedInstance] exitlogon];
  124. //销毁之前的单利对象
  125. // [NewBasicTabbarController objectDealloc];
  126. // if (!alertViewLog) {
  127. // alertViewLog = [[UIAlertView alloc]initWithTitle:@"系统提示" message:@"登录已过期,请重新登录!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
  128. // [alertViewLog show];
  129. // }
  130. }
  131. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  132. {
  133. [alertViewLog removeFromSuperview];
  134. alertViewLog = nil;
  135. //删除已绑定的推送对象
  136. [[JPushHelper sharedInstance] deleteAlias];
  137. //销毁本地数据
  138. [[NewInterfaceReplacement sharedInstance] replacementLogin];
  139. }
  140. #pragma mark - APNs注册成功回调,将返回的deviceToken上传到CloudPush服务器
  141. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  142. [[JPushHelper sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
  143. }
  144. #pragma mark - APNs注册失败回调
  145. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  146. [[JPushHelper sharedInstance] application:application didFailToRegisterForRemoteNotificationsWithError:error];
  147. }
  148. #pragma mark - 基于iOS6及以下的系统版本 旧的API处理收到的推送消息通知
  149. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  150. //收到通知消息
  151. [[JPushHelper sharedInstance] application:application didReceiveRemoteNotification:userInfo];
  152. }
  153. #pragma mark - APP处于前台 基于iOS10 新的API处理收到的推送消息通知
  154. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  155. //应用在前台收到通知
  156. [[JPushHelper sharedInstance] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler];
  157. }
  158. #pragma mark - APP处于后台/未启动 新的API处理收到的推送消息通知
  159. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
  160. //点击通知进入应用
  161. [[JPushHelper sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:(void (^)())completionHandler];
  162. }
  163. #pragma mark - 基于iOS7~iOS9 旧的API处理收到的推送消息通知
  164. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  165. {
  166. [[JPushHelper sharedInstance] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:(void (^)())completionHandler];
  167. }
  168. #pragma mark - 本地推送通知API 处理收到的推送消息通知
  169. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  170. [[JPushHelper sharedInstance] application:application didReceiveLocalNotification:notification];
  171. }
  172. #pragma mark - 基于iOS9以前 旧的API处理第三方跳转本应用收到的URL与值
  173. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  174. {
  175. //NSLog(@"欢迎回来 Url : %@",[url.absoluteString urlDecodedString]);
  176. if ([url.host isEqualToString:@"safepay"]) {
  177. //如果APP处于后台,则通过此方法拿到支付宝的回调信息
  178. // return [[AlipaySDKHelper sharedInstance]application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
  179. }else if ([url.host isEqualToString:@"pay"]) {
  180. //处理微信回调信息
  181. // return [[WXSDKHelper sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
  182. }
  183. /*
  184. else {
  185. //其它通过项目协议唤醒APP
  186. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  187. [[NSNotificationCenter defaultCenter]postNotificationName:MMNotificationMessage object:url userInfo:@{mmNotificationMessageType:mmNotificationMessageUrl}];
  188. });
  189. }
  190. */
  191. return YES;
  192. }
  193. #pragma mark - 基于iOS9以后 新的API处理第三方跳转本应用收到的URL与值
  194. -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options
  195. {
  196. //NSLog(@"欢迎回来 Url : %@",[url.absoluteString urlDecodedString]);
  197. if ([url.host isEqualToString:@"safepay"]) {
  198. //如果APP处于后台,则通过此方法拿到支付宝的回调信息
  199. // return [[AlipaySDKHelper sharedInstance]application:application openURL:url options:options];
  200. //
  201. }else if ([url.host isEqualToString:@"pay"]) {
  202. //处理微信回调信息
  203. // return [[WXSDKHelper sharedInstance] application:application openURL:url options:options];
  204. }
  205. /*
  206. else {
  207. //其它通过项目协议唤醒APP
  208. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  209. [[NSNotificationCenter defaultCenter]postNotificationName:MMNotificationMessage object:url userInfo:@{mmNotificationMessageType:mmNotificationMessageUrl}];
  210. });
  211. }
  212. */
  213. return YES;
  214. }
  215. #pragma mark - 应用程序进入非活跃状态(接听电话)
  216. - (void)applicationWillResignActive:(UIApplication *)application {
  217. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  218. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  219. }
  220. #pragma mark - 应用程序进入后台
  221. - (void)applicationDidEnterBackground:(UIApplication *)application {
  222. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  223. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  224. [[EMClient sharedClient] applicationDidEnterBackground:application];
  225. }
  226. #pragma mark - 应用程序进入前台
  227. - (void)applicationWillEnterForeground:(UIApplication *)application {
  228. // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
  229. [[EMClient sharedClient] applicationWillEnterForeground:application];
  230. }
  231. #pragma mark - 应用程序启动(重启)
  232. - (void)applicationDidBecomeActive:(UIApplication *)application {
  233. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  234. [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
  235. }
  236. #pragma mark - 应用程序终止时
  237. - (void)applicationWillTerminate:(UIApplication *)application {
  238. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  239. //释放公共通知对象
  240. [[NSNotificationCenter defaultCenter] removeObserver:self name:NewJitaoServerPublicNotification object:nil];
  241. NSLog(@"应用程序终止时");
  242. }
  243. @end