// // UIResponder+SPSBDelegate.m // 我的社保 // // Created by jiaxian_he on 2021/4/17. // #import "UIResponder+SPSBDelegate.h" #import "SPSBBusinessManager.h" #import "SPSBGeneralManager.h" #import #import "SPSBKeyProfile.h" #import #import "AppDelegate+SPSBAutoLogin.h" #import "AppDelegate+SPSBHandleData.h" #import "SPSBNotificationDelegateManager.h" #import "SPSBCustomerServiceManager.h" #import "WXApi.h" #import #import #import #import "SPSBNotificationDelegateManager.h" static bool spsb_isFirstLaunch = true; @interface UIResponder () @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