123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // UIResponder+SPSBDelegate.m
- // 我的社保
- //
- // Created by jiaxian_he on 2021/4/17.
- //
- #import "UIResponder+SPSBDelegate.h"
- #import "SPSBBusinessManager.h"
- #import "SPSBGeneralManager.h"
- #import <SobotKit/SobotKit.h>
- #import "SPSBKeyProfile.h"
- #import <JXHSystemShortcut.h>
- #import "AppDelegate+SPSBAutoLogin.h"
- #import "AppDelegate+SPSBHandleData.h"
- #import "SPSBNotificationDelegateManager.h"
- #import "SPSBCustomerServiceManager.h"
- #import "WXApi.h"
- #import <TencentOpenAPI/QQApiInterface.h>
- #import <TencentOpenAPI/TencentOAuth.h>
- #import <AlipaySDK/AlipaySDK.h>
- #import "SPSBNotificationDelegateManager.h"
- static bool spsb_isFirstLaunch = true;
- @interface UIResponder ()<WXApiDelegate>
- @end
- @implementation UIResponder (SPSBDelegate)
- - (bool)spsb_responder:(UIResponder *)responder continueUserActivity:(NSUserActivity *)userActivity {
- if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
- NSURL *url = userActivity.webpageURL;
- if (!url) {
- return true;
- }
- if ([TencentOAuth CanHandleUniversalLink:url]) {
- return [QQApiInterface handleOpenUniversallink:url delegate:nil];
- }
- [WXApi handleOpenUniversalLink:userActivity delegate:self];
- }
- return true;
- }
- - (bool)spsb_responder:(UIResponder *)responder openURL:(NSURL *)url {
- if ([url.host isEqualToString:@"safepay"]) {
- //跳转支付宝钱包进行支付,处理支付结果
- [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
- spsb_postNotification(SPSBPayNotificationKey, @selector(spsb_payResultWithType:data:), spsb_payResultWithType:SPSBPayTypeAlipay data:resultDic);
- }];
- return true;
- }
- [WXApi handleOpenURL:url delegate:self];
- return true;
- }
- - (void)onResp:(BaseResp*)resp {
- if([resp isKindOfClass:[PayResp class]]){
- //支付返回结果,实际支付结果需要去微信服务器端查询
- spsb_postNotification(SPSBPayNotificationKey, @selector(spsb_payResultWithType:data:), spsb_payResultWithType:SPSBPayTypeWechet data:[NSNumber numberWithInt:resp.errCode]);
- }
- }
- - (void)spsb_didBecomeActive:(UIResponder *)responder {
- debugLog(@"active");
- [[ZCLibClient getZCLibClient] checkIMConnected];
- NSDate *new = [NSDate new];
- spsb_setAppActive(true);
- [jxh_application() setApplicationIconBadgeNumber:0];
- if (spsb_isFirstLaunch) {
- spsb_isFirstLaunch = false;
- } else if (!spsb_customerServiceManager().spsb_isClickNotification) {
- NSDate *lastEnterBackgroundTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBResignActiveTime]];
- NSDate *shouldCheckSobotTime = [NSDate dateWithTimeInterval:5 * 60 sinceDate:lastEnterBackgroundTime];
- if ([new compare:shouldCheckSobotTime] >= 0) {
- [spsb_customerServiceManager() checkSobot];
- }
- }
- }
- - (void)spsb_willResignActive:(UIResponder *)responder {
- [[ZCLibClient getZCLibClient] removeIMAllObserver];
- spsb_setAppActive(false);
- NSDate *new = [NSDate new];
- [jxh_userDefaults() setObject:[jxh_dateFormatter() stringFromDate:new] forKey:SPSBResignActiveTime];
- [jxh_userDefaults() synchronize];
- debugLog(@"applicationWillResignActive---finishSaveTime");
- }
- - (void)spsb_willEnterForeground:(UIResponder *)responder {
- debugLog(@"enterForeground");
- if (spsb_isFirstLaunch) {
- return;
- }
- NSDate *new = [NSDate new];
- debugLog(@"%@", new);
- NSDate *lastEnterBackgroundTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBEntryBackgroundTime]];
- NSDate *shouldRefreshStatusTime = [NSDate dateWithTimeInterval:25 * 60 sinceDate:lastEnterBackgroundTime];
- if ([new compare:shouldRefreshStatusTime] >= 0) {
- [jxh_appDelegate() getProfile];
- [jxh_appDelegate() judgeLogin];
- }
- NSDate *lastNormalRefreshTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBShebaoNormalRefreshTime]];
- NSDate *shouldRefreshTime = [NSDate dateWithTimeInterval:86400 sinceDate:lastNormalRefreshTime];
- NSDate *lastSupplementaryPayRefreshTime = [jxh_dateFormatter() dateFromString:[jxh_userDefaults() objectForKey:SPSBShebaoSupplementaryPayRefreshTime]];
- NSDate *_shouldRefreshTime = [NSDate dateWithTimeInterval:86400 sinceDate:lastSupplementaryPayRefreshTime];
- if ([new compare:shouldRefreshTime] >= 0) {
- spsb_postNotification(SPSBPurchaseNotificationKey, @selector(spsb_shouldRefreshPurchaseStatus), spsb_shouldRefreshPurchaseStatus);
- }
- if ([new compare:_shouldRefreshTime] >= 0) {
- spsb_postNotification(SPSBPurchaseNotificationKey, @selector(spsb_shouldRefreshSupplementaryPayStatus), spsb_shouldRefreshSupplementaryPayStatus);
- }
- }
- - (void)spsb_didEnterBackground:(UIResponder *)responder {
- NSDate *new = [NSDate new];
- [jxh_userDefaults() setObject:[jxh_dateFormatter() stringFromDate:new] forKey:SPSBEntryBackgroundTime];
- [jxh_userDefaults() synchronize];
- debugLog(@"applicationDidEnterBackground---finishSaveTime");
- }
- @end
|