当前位置:   article > 正文

[iOS]AppDelegate的分类使用_[url.host isequaltostring:@"wapoauth"]

[url.host isequaltostring:@"wapoauth"]

AppDelegate是管理整个应用程序生命周期的一个类, 之前我还会在这个类中处理很多第三方库的集成和其他功能, 比如:推送/分享/统计/启动页/引导页/广告/Bugly/版本检查/数据更新 等等. 最后导致AppDelegate非常臃肿, 不利于阅读.
最近发现,使用拓展的方式将各个功能的逻辑分离开来,能够让程序结构更清晰更优雅.

  1. #import "AppDelegate.h"
  2. #import "AppDelegate+WeChat.h"
  3. #import "AppDelegate+CheckVersion.h"
  4. #import "AppDelegate+Service.h"
  5. #import "AppDelegate+AliPush.h"
  6. #import "AppDelegate+UMAnalysis.h"
  7. #import "AppDelegate+UMShare.h"
  8. #import "AppDelegate+ShortcutTouch.h"
  9. #import "AppDelegate+Score.h"
  10. #import "AppDelegate+AppSign.h"
  11. #import "AppDelegate+LaunchAD.h"
  12. #import "AppDelegate+StartNumber.h"
  13. #import "AppDelegate+Insterest.h"
  14. #import "AppDelegate+GuidePage.h"
  15. #import "AppDelegate+CheckData.h"
  16. #import "AppDelegate+Pangolin.h"
  17. #import "AppDelegate+NightMode.h"
  18. #import "AppDelegate+Bugly.h"
  19. #import "AppDelegate+ReadTime.h"
  20. #import "CYLTabBarController.h"
  21. #import "IAPManager.h"
  22. #import <UMShare/UMShare.h>
  23. @interface AppDelegate ()
  24. @end
  25. @implementation AppDelegate
  26. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  27. // Override point for customization after application launch.
  28. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  29. self.tabBarControllerConfig = [[WXYZ_MainTabbarViewController alloc] init];
  30. CYLTabBarController *tabBarController = self.tabBarControllerConfig.tabBarController;
  31. [self.window setRootViewController:tabBarController];
  32. // 检查数据更改
  33. [self initCheckData];
  34. // 夜览模式
  35. [self initNightModeState];
  36. // 检查更新
  37. [self checkVersionCallBack:^(NSUInteger updateState) {}];
  38. // 开启广告
  39. [self initADManager];
  40. // 启动页
  41. [self initLaunchADView];
  42. // 引导页
  43. [self initGuidePageView];
  44. //开启阿里推送
  45. [self initAliPushWithApplication:application launchOptions:launchOptions];
  46. // 友盟
  47. [self initUMAnalysis];
  48. // 分享
  49. [self initUMShare];
  50. // 3D Touch
  51. [self initShortcutTouch];
  52. // 应用内好评
  53. [self initAppStoreScore];
  54. // bug统计
  55. [self initBugly];
  56. // 阅读时长
  57. [self initReadingTime];
  58. #if WX_Super_Member_Mode || WX_Recharge_Mode
  59. // 启动IAP
  60. [[IAPManager shared] startManager];
  61. #endif
  62. // 微信
  63. [self registerWeChat];
  64. // 签到
  65. [self initUserSign];
  66. // 显示沙盒地址
  67. [self showHome];
  68. return YES;
  69. }
  70. - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  71. [self initStartNumber];
  72. return YES;
  73. }
  74. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  75. if ([[url host] isEqualToString:@"platformId=wechat"]) {
  76. return [[UMSocialManager defaultManager] handleOpenURL:url];
  77. }
  78. if ([[url host] isEqualToString:@"oauth"]) {
  79. return [WXApi handleOpenURL:url delegate:self];
  80. }
  81. return YES;
  82. }
  83. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
  84. if ([[UMSocialManager defaultManager] handleOpenURL:url]) {
  85. return YES;
  86. }
  87. return [WXApi handleOpenURL:url delegate:self];
  88. }
  89. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  90. if ([[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation]) {
  91. return YES;
  92. }
  93. return [WXApi handleOpenURL:url delegate:self];
  94. }
  95. - (void)applicationWillResignActive:(UIApplication *)application {
  96. // 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.
  97. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  98. }
  99. - (void)applicationDidEnterBackground:(UIApplication *)application {
  100. // 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.
  101. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  102. }
  103. - (void)applicationWillEnterForeground:(UIApplication *)application {
  104. // 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.
  105. }
  106. - (void)applicationDidBecomeActive:(UIApplication *)application {
  107. // 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.
  108. application.applicationIconBadgeNumber = 0;
  109. if (self.forcedUpdateTitle) {
  110. [self showUpdateView];
  111. }
  112. }
  113. - (void)applicationWillTerminate:(UIApplication *)application {
  114. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  115. /**结束IAP工具类*/
  116. [[IAPManager shared] stopManager];
  117. }
  118. @end





 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/124897
推荐阅读
相关标签
  

闽ICP备14008679号