UIResponder+SPSBDelegate.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // UIResponder+SPSBDelegate.m
  3. // 我的社保
  4. //
  5. // Created by jiaxian_he on 2021/4/17.
  6. //
  7. #import "UIResponder+SPSBDelegate.h"
  8. #import "SPSBBusinessManager.h"
  9. #import "SPSBGeneralManager.h"
  10. #import <SobotKit/SobotKit.h>
  11. #import "SPSBKeyProfile.h"
  12. #import <JXHSystemShortcut.h>
  13. #import "AppDelegate+SPSBAutoLogin.h"
  14. #import "AppDelegate+SPSBHandleData.h"
  15. #import "SPSBNotificationDelegateManager.h"
  16. #import "SPSBCustomerServiceManager.h"
  17. #import "WXApi.h"
  18. #import <TencentOpenAPI/QQApiInterface.h>
  19. #import <TencentOpenAPI/TencentOAuth.h>
  20. #import <AlipaySDK/AlipaySDK.h>
  21. #import "SPSBNotificationDelegateManager.h"
  22. static bool spsb_isFirstLaunch = true;
  23. @interface UIResponder ()<WXApiDelegate>
  24. @end
  25. @implementation UIResponder (SPSBDelegate)
  26. - (bool)spsb_responder:(UIResponder *)responder continueUserActivity:(NSUserActivity *)userActivity {
  27. if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
  28. NSURL *url = userActivity.webpageURL;
  29. if (!url) {
  30. return true;
  31. }
  32. if ([TencentOAuth CanHandleUniversalLink:url]) {
  33. return [QQApiInterface handleOpenUniversallink:url delegate:nil];
  34. }
  35. [WXApi handleOpenUniversalLink:userActivity delegate:self];
  36. }
  37. return true;
  38. }
  39. - (bool)spsb_responder:(UIResponder *)responder openURL:(NSURL *)url {
  40. if ([url.host isEqualToString:@"safepay"]) {
  41. //跳转支付宝钱包进行支付,处理支付结果
  42. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  43. spsb_postNotification(SPSBPayNotificationKey, @selector(spsb_payResultWithType:data:), spsb_payResultWithType:SPSBPayTypeAlipay data:resultDic);
  44. }];
  45. return true;
  46. }
  47. [WXApi handleOpenURL:url delegate:self];
  48. return true;
  49. }
  50. - (void)onResp:(BaseResp*)resp {
  51. if([resp isKindOfClass:[PayResp class]]){
  52. //支付返回结果,实际支付结果需要去微信服务器端查询
  53. spsb_postNotification(SPSBPayNotificationKey, @selector(spsb_payResultWithType:data:), spsb_payResultWithType:SPSBPayTypeWechet data:[NSNumber numberWithInt:resp.errCode]);
  54. }
  55. }
  56. - (void)spsb_didBecomeActive:(UIResponder *)responder {
  57. debugLog(@"active");
  58. [[ZCLibClient getZCLibClient] checkIMConnected];
  59. NSDate *new = [NSDate new];
  60. spsb_setAppActive(true);
  61. [jxh_application() setApplicationIconBadgeNumber:0];
  62. if (spsb_isFirstLaunch) {
  63. spsb_isFirstLaunch = false;
  64. } else if (!spsb_customerServiceManager().spsb_isClickNotification) {
  65. NSDate *lastEnterBackgroundTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBResignActiveTime]];
  66. NSDate *shouldCheckSobotTime = [NSDate dateWithTimeInterval:5 * 60 sinceDate:lastEnterBackgroundTime];
  67. if ([new compare:shouldCheckSobotTime] >= 0) {
  68. [spsb_customerServiceManager() checkSobot];
  69. }
  70. }
  71. }
  72. - (void)spsb_willResignActive:(UIResponder *)responder {
  73. [[ZCLibClient getZCLibClient] removeIMAllObserver];
  74. spsb_setAppActive(false);
  75. NSDate *new = [NSDate new];
  76. [jxh_userDefaults() setObject:[jxh_dateFormatter() stringFromDate:new] forKey:SPSBResignActiveTime];
  77. [jxh_userDefaults() synchronize];
  78. debugLog(@"applicationWillResignActive---finishSaveTime");
  79. }
  80. - (void)spsb_willEnterForeground:(UIResponder *)responder {
  81. debugLog(@"enterForeground");
  82. if (spsb_isFirstLaunch) {
  83. return;
  84. }
  85. NSDate *new = [NSDate new];
  86. debugLog(@"%@", new);
  87. NSDate *lastEnterBackgroundTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBEntryBackgroundTime]];
  88. NSDate *shouldRefreshStatusTime = [NSDate dateWithTimeInterval:25 * 60 sinceDate:lastEnterBackgroundTime];
  89. if ([new compare:shouldRefreshStatusTime] >= 0) {
  90. [jxh_appDelegate() getProfile];
  91. [jxh_appDelegate() judgeLogin];
  92. }
  93. NSDate *lastNormalRefreshTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBShebaoNormalRefreshTime]];
  94. NSDate *shouldRefreshTime = [NSDate dateWithTimeInterval:86400 sinceDate:lastNormalRefreshTime];
  95. NSDate *lastSupplementaryPayRefreshTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBShebaoSupplementaryPayRefreshTime]];
  96. NSDate *_shouldRefreshTime = [NSDate dateWithTimeInterval:86400 sinceDate:lastSupplementaryPayRefreshTime];
  97. if ([new compare:shouldRefreshTime] >= 0) {
  98. spsb_postNotification(SPSBPurchaseNotificationKey, @selector(spsb_shouldRefreshPurchaseStatus), spsb_shouldRefreshPurchaseStatus);
  99. }
  100. if ([new compare:_shouldRefreshTime] >= 0) {
  101. spsb_postNotification(SPSBPurchaseNotificationKey, @selector(spsb_shouldRefreshSupplementaryPayStatus), spsb_shouldRefreshSupplementaryPayStatus);
  102. }
  103. }
  104. - (void)spsb_didEnterBackground:(UIResponder *)responder {
  105. NSDate *new = [NSDate new];
  106. [jxh_userDefaults() setObject:[jxh_dateFormatter() stringFromDate:new] forKey:SPSBEntryBackgroundTime];
  107. [jxh_userDefaults() synchronize];
  108. debugLog(@"applicationDidEnterBackground---finishSaveTime");
  109. }
  110. @end