SPSBStartPageViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // SPSBStartPageViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/20.
  6. //
  7. #import "SPSBStartPageViewController.h"
  8. #import "AppDelegate+SPSBRootViewController.h"
  9. #import <JXHSystemShortcut.h>
  10. #import "SPSBUIGeneralHeader.h"
  11. #import "SPSBNotificationDelegateManager.h"
  12. #import "SPSBOpenADManager.h"
  13. #import "SPSBKeyProfile.h"
  14. #import "SPSBGuideViewController.h"
  15. @interface SPSBStartPageViewController ()<SPSBNotificationDelegate> {
  16. bool _isFirst;
  17. }
  18. @end
  19. @implementation SPSBStartPageViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. _isFirst = true;
  23. [self setupUI];
  24. }
  25. - (void)dealloc {
  26. spsb_removeNotificationKey(SPSBOpenAdNotificationKey);
  27. }
  28. - (void)viewDidAppear:(BOOL)animated {
  29. [super viewDidAppear:animated];
  30. if (_isFirst) {
  31. _isFirst = false;
  32. } else {
  33. [jxh_appDelegate() showHomePage];
  34. return;
  35. }
  36. bool needJudge = [self judgeVersion];
  37. if (!needJudge) {
  38. return;
  39. }
  40. switch (spsb_openADManager().spsb_switchStatus) {
  41. case SPSBOpenAdSwitchStatusForbid: {
  42. [jxh_appDelegate() showHomePage];
  43. }
  44. break;
  45. case SPSBOpenAdSwitchStatusUnknow: {
  46. spsb_setNotificationKey(SPSBOpenAdNotificationKey);
  47. [self performSelector:@selector(removeOpenAD) withObject:nil afterDelay:1];
  48. }
  49. break;
  50. default: [self judgeOpenAD];
  51. break;
  52. }
  53. }
  54. #pragma mark - JUDGE VERSION
  55. - (bool)judgeVersion {
  56. if (![jxh_userDefaults() objectForKey:SPSBAppInsideVersion]) {
  57. [self setAppInsideVerson];
  58. [self creatGuidanceView];
  59. return false;
  60. } else {
  61. //首页提示展示
  62. if ([[jxh_userDefaults() objectForKey:SPSBAppInsideVersion] integerValue] < 25 && SPSBCurrentVersion == 25) {
  63. NSMutableDictionary *dic = [[jxh_userDefaults() objectForKey:SPSBTipsMark] mutableCopy];
  64. dic[@"home"] = @"1";
  65. [jxh_userDefaults() setObject:dic forKey:SPSBTipsMark];
  66. [self setAppInsideVerson];
  67. [jxh_appDelegate() changeTabBarType:SPSBTabBarTypeHome];
  68. return false;
  69. } else if ([[jxh_userDefaults() objectForKey:SPSBAppInsideVersion] integerValue] < SPSBCurrentVersion) {
  70. //每次更新都展示引导页
  71. [self setAppInsideVerson];
  72. [self creatGuidanceView];
  73. return false;
  74. } else {
  75. [self setAppInsideVerson];
  76. return true;
  77. }
  78. }
  79. }
  80. - (void)setAppInsideVerson {
  81. [jxh_userDefaults() setObject:[NSString localizedStringWithFormat:@"%ld", (long)SPSBCurrentVersion] forKey:SPSBAppInsideVersion];
  82. [jxh_userDefaults() synchronize];
  83. }
  84. - (void)judgeOpenAD {
  85. if (spsb_openADManager().spsb_switchStatus == SPSBOpenAdSwitchStatusOn) {
  86. [self setOpenAD];
  87. } else {
  88. [jxh_appDelegate() showHomePage];
  89. }
  90. }
  91. - (void)setOpenAD {
  92. [spsb_openADManager() showAD];
  93. }
  94. - (void)removeOpenAD {
  95. dispatch_main_async_safe(^{
  96. [jxh_appDelegate() showHomePage];
  97. });
  98. }
  99. #pragma mark - SPSBNotificationDelegate
  100. - (void)spsb_gotOpenAdData {
  101. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(removeOpenAD) object:nil];
  102. [self judgeOpenAD];
  103. }
  104. #pragma mark - GuidanceView
  105. - (void)creatGuidanceView {
  106. SPSBGuideViewController *guideViewController = SPSBGuideViewController.new;
  107. guideViewController.modalPresentationStyle = UIModalPresentationCustom;
  108. @weakify(self)
  109. guideViewController.spsb_nextAction = ^{
  110. @strongify(self)
  111. [jxh_appDelegate() showHomePage];
  112. [self dismissViewControllerAnimated:false completion:nil];
  113. };
  114. [self presentViewController:guideViewController animated:false completion:^{
  115. }];
  116. }
  117. #pragma mark - UI
  118. - (void)setupUI {
  119. UIImageView *imageView = [[UIImageView alloc] initWithImage:jxh_getImage(startpage)];
  120. imageView.contentMode = UIViewContentModeScaleAspectFit;
  121. [self.view addSubview:imageView];
  122. [imageView makeConstraints:^(JXHConstraintMaker *make) {
  123. make.leading.and.trailing.equalTo(0);
  124. make.centerY.equalTo(self.view);
  125. make.height.equalTo(1200);
  126. }];
  127. imageView = [[UIImageView alloc] initWithImage:jxh_getImage(star_page_bottom)];
  128. [self.view addSubview:imageView];
  129. [imageView makeConstraints:^(JXHConstraintMaker *make) {
  130. make.centerX.equalTo(self.view);
  131. make.bottom.equalTo(-44);
  132. }];
  133. }
  134. @end