AppDelegate+SPSBPopup.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // AppDelegate+SPSBPopup.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/27.
  6. //
  7. #import "AppDelegate+SPSBPopup.h"
  8. #import "SPSBAppProfileModel.h"
  9. #import <JXHSystemShortcut.h>
  10. #import "SPSBKeyProfile.h"
  11. #import "SPSBBusinessManager.h"
  12. #import "SPSBNetworkManager.h"
  13. #import "SPSBURLApiProfile.h"
  14. #import "SPSBPopupADViewController.h"
  15. #import "SPSBOpenPopupManager.h"
  16. #import "SPSBPrivacyViewController.h"
  17. #import <StoreKit/StoreKit.h>
  18. #import "SPSBAppCommentViewController.h"
  19. @implementation AppDelegate (SPSBPopup)
  20. - (void)judegePopup {
  21. if (![jxh_userDefaults() objectForKey:SPSBPersonalPrivacy]) {
  22. [self showPrivacy];
  23. }
  24. [self judgeIsNeedToComment];
  25. }
  26. #pragma mark - 隐私
  27. - (void)showPrivacy {
  28. SPSBPrivacyViewController *vc = SPSBPrivacyViewController.new;
  29. SPSBOpenPopupModel *model = SPSBOpenPopupModel.new;
  30. model.spsb_popup = vc;
  31. [SPSBOpenPopupManager insertPopup:model];
  32. }
  33. #pragma mark - 评论
  34. - (void)judgeIsNeedToComment {
  35. if ([jxh_userDefaults() objectForKey:SPSBFirstOpenApp]) {
  36. if (![jxh_userDefaults() objectForKey:SPSBCommentApp]) {
  37. [self performSelector:@selector(autoShowComment) withObject:nil afterDelay:30];
  38. }
  39. } else {
  40. [jxh_userDefaults() setObject:@(true) forKey:SPSBFirstOpenApp];
  41. [jxh_userDefaults() synchronize];
  42. }
  43. }
  44. - (void)autoShowComment {
  45. [jxh_userDefaults() setObject:@(true) forKey:SPSBCommentApp];
  46. [jxh_userDefaults() synchronize];
  47. if (@available(iOS 10.3, *)) {
  48. [SKStoreReviewController requestReview];
  49. return;
  50. }
  51. SPSBAppCommentViewController *vc = SPSBAppCommentViewController.new;
  52. SPSBOpenPopupModel *model = SPSBOpenPopupModel.new;
  53. model.spsb_popup = vc;
  54. [SPSBOpenPopupManager insertPopup:model];
  55. }
  56. #pragma mark - 广告弹框
  57. - (void)judgeAdPopup:(SPSBAppPopImageModel *)data {
  58. if (![[jxh_userDefaults() objectForKey:SPSBPopupADImagePath] isEqualToString:data.spsb_img]) {
  59. [self getAdPopoutImageWithData:data];
  60. return;
  61. }
  62. NSDate *new = [NSDate new];
  63. NSDate *lastPopTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBPopupADTime]];
  64. if (lastPopTime) {
  65. NSDate *shouldPopTime = [NSDate dateWithTimeInterval:24 * 60 * 60 sinceDate:lastPopTime];
  66. if ([new compare:shouldPopTime] >= 0) {
  67. [self getAdPopoutImageWithData:data];
  68. }
  69. } else {
  70. [self getAdPopoutImageWithData:data];
  71. }
  72. }
  73. - (void)getAdPopoutImageWithData:(SPSBAppPopImageModel *)model {
  74. [spsb_globalNetworkManager() networkDownloadImageWithUrl:spsb_fileUrl(model.spsb_img) key:@"getAdPopoutImage" completion:^(NSError * _Nonnull error, id _Nullable data) {
  75. if (error.code == SPSBNetworkErrorCodeSuccess && data[@"image"]) {
  76. [self showAdPopoutWithImage:data[@"image"] data:model];
  77. }
  78. }];
  79. }
  80. - (void)showAdPopoutWithImage:(UIImage *)image data:(SPSBAppPopImageModel *)data {
  81. SPSBPopupADViewController *vc = SPSBPopupADViewController.new;
  82. vc.spsb_data = data;
  83. vc.spsb_image = image;
  84. SPSBOpenPopupModel *model = SPSBOpenPopupModel.new;
  85. model.spsb_popup = vc;
  86. [SPSBOpenPopupManager insertPopup:model];
  87. }
  88. @end