diff --git a/XinjiangProject/XinjiangProject/Define/StatusMacros.h b/XinjiangProject/XinjiangProject/Define/StatusMacros.h index 993db1b..17994cd 100755 --- a/XinjiangProject/XinjiangProject/Define/StatusMacros.h +++ b/XinjiangProject/XinjiangProject/Define/StatusMacros.h @@ -84,8 +84,8 @@ // 最新地址 //#define Http @"http://192.168.1.47"//王昊 -//#define Http @"https://xj-api.mcrm.vip:8888"// -#define Http @"http://192.168.1.47"//王昊 +#define Http @"https://xj-api.mcrm.vip:8888"// +//#define Http @"http://192.168.1.47"//王昊 #define H5DevHost @"xj-api.mcrm.vip:8888"// #define IntervenH5 @"https://xj-admin.mcrm.vip:8888" #define SCHEME @"https" // diff --git a/XinjiangProject/XinjiangProject/Project/Base/XJBaseWebViewVC.m b/XinjiangProject/XinjiangProject/Project/Base/XJBaseWebViewVC.m index 6054aeb..c97ed01 100644 --- a/XinjiangProject/XinjiangProject/Project/Base/XJBaseWebViewVC.m +++ b/XinjiangProject/XinjiangProject/Project/Base/XJBaseWebViewVC.m @@ -9,13 +9,37 @@ @interface XJBaseWebViewVC () -@property (nonatomic, strong)NSURL *originalUrl; -@property (nonatomic, copy)NSString *videoUrl; -@property (nonatomic, copy)NSString *messageType; +// 以下三个属性声明后未使用,暂时保留 +//@property (nonatomic, strong)NSURL *originalUrl; +//@property (nonatomic, copy)NSString *videoUrl; +//@property (nonatomic, copy)NSString *messageType; @end +// ── 弱引用代理 ────────────────────────────────────────────────────────────── +// WKUserContentController 对 addScriptMessageHandler 的 handler 是强引用。 +// 如果直接传 self,self → wkWebView → configuration → userContentController → self, +// 形成循环引用,VC 永远无法释放。 +// 解决方案:用一个弱引用中间对象转发消息。 +@interface XJWeakScriptMessageHandler : NSObject +@property (nonatomic, weak) id delegate; ++ (instancetype)handlerWithDelegate:(id)delegate; +@end + +@implementation XJWeakScriptMessageHandler ++ (instancetype)handlerWithDelegate:(id)delegate { + XJWeakScriptMessageHandler *handler = [[XJWeakScriptMessageHandler alloc] init]; + handler.delegate = delegate; + return handler; +} +- (void)userContentController:(WKUserContentController *)userContentController + didReceiveScriptMessage:(WKScriptMessage *)message { + [self.delegate userContentController:userContentController didReceiveScriptMessage:message]; +} +@end +// ──────────────────────────────────────────────────────────────────────────── + @implementation XJBaseWebViewVC @@ -32,10 +56,18 @@ } - (void)backVC { - + [self.navigationController popViewControllerAnimated:YES]; } +- (void)dealloc { + // 移除所有 scriptMessageHandler,配合 XJWeakScriptMessageHandler 彻底避免内存泄漏 + WKUserContentController *ucc = self.wkWebView.configuration.userContentController; + [ucc removeScriptMessageHandlerForName:@"JSCallback"]; + [ucc removeScriptMessageHandlerForName:@"htmlBack"]; + [ucc removeScriptMessageHandlerForName:@"finishActivity"]; +} + - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; if (_wkWebView) { @@ -51,14 +83,14 @@ [super viewWillDisappear:animated]; _wkWebView.navigationDelegate = nil; _wkWebView.UIDelegate = nil; - //清除cookies - NSHTTPCookie *cookie; - NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; - for (cookie in [storage cookies]) { - [storage deleteCookie:cookie]; - } - [[NSURLCache sharedURLCache] removeAllCachedResponses]; - [self clearWebViewCache]; + // ⚠️ 以下代码会清除整个 App 的所有 Cookie,影响其他模块登录状态,已注释 +// NSHTTPCookie *cookie; +// NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; +// for (cookie in [storage cookies]) { +// [storage deleteCookie:cookie]; +// } +// [[NSURLCache sharedURLCache] removeAllCachedResponses]; +// [self clearWebViewCache]; } #pragma mark - Create UI @@ -69,18 +101,36 @@ preferences.javaScriptCanOpenWindowsAutomatically = YES; preferences.minimumFontSize = 10; configuration.preferences = preferences; - [configuration.userContentController addScriptMessageHandler:self name:@"JSCallback"]; - [configuration.userContentController addScriptMessageHandler:self name:@"htmlBack"]; + + // ── 统一使用 configuration 自带的 userContentController ────────────────── + // Bug 修复:原先在下方又新建了 wkUController 并覆盖 configuration.userContentController, + // 导致此处注册的 JSCallback / htmlBack 被丢弃,永远收不到 JS 消息。 + // Bug 修复:改用 XJWeakScriptMessageHandler 代理,防止循环引用内存泄漏。 + XJWeakScriptMessageHandler *weakHandler = [XJWeakScriptMessageHandler handlerWithDelegate:self]; + [configuration.userContentController addScriptMessageHandler:weakHandler name:@"JSCallback"]; + [configuration.userContentController addScriptMessageHandler:weakHandler name:@"htmlBack"]; + [configuration.userContentController addScriptMessageHandler:weakHandler name:@"finishActivity"]; // 不带参数的调用 + + // 原写法(已废弃):直接传 self 会造成循环引用 +// [configuration.userContentController addScriptMessageHandler:self name:@"JSCallback"]; +// [configuration.userContentController addScriptMessageHandler:self name:@"htmlBack"]; + // ──────────────────────────────────────────────────────────────────────── + //防止搜索框自动放大 注入js代码 - WKUserContentController *userController = [WKUserContentController new]; + // 原代码中 userController 声明后从未使用,已移除 +// WKUserContentController *userController = [WKUserContentController new]; NSString *jScript = @"var script = document.createElement('meta');script.name = 'viewport';script.content='width=device-width,user-scalable=no';document.getElementsByTagName('head')[0].appendChild(script);"; WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]; - WKUserContentController * wkUController = [[WKUserContentController alloc] init]; - [wkUController addScriptMessageHandler: self name: @"finishActivity"];//不带参数的调用 - [wkUController addUserScript:wkUScript]; - configuration.userContentController= wkUController; + // 原写法(已废弃):新建 wkUController 并覆盖 configuration.userContentController, + // 导致上方注册的 JSCallback / htmlBack 全部失效 +// WKUserContentController * wkUController = [[WKUserContentController alloc] init]; +// [wkUController addScriptMessageHandler: self name: @"finishActivity"]; +// [wkUController addUserScript:wkUScript]; +// configuration.userContentController = wkUController; + + [configuration.userContentController addUserScript:wkUScript]; self.wkWebView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, MyViewHEIGHT) configuration:configuration]; self.wkWebView.navigationDelegate = self; @@ -201,10 +251,13 @@ #pragma mark - 自定义 - (void)onBackClicked{ - if ( self.wkWebView.canGoBack){ + if (self.wkWebView.canGoBack) { [self.wkWebView goBack]; } else { + // 原写法:只清缓存没有 pop,页面会卡住 +// [self clearWebViewCache]; [self clearWebViewCache]; + [self.navigationController popViewControllerAnimated:YES]; } } @@ -226,19 +279,18 @@ } } - (NSString *)URLEncodedString:(NSString *)urlString{ - NSString *encodePath ; - if (!IOS7) { - encodePath = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - }else{ + NSString *encodePath; + encodePath = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; - }return encodePath; + return encodePath; } #pragma mark - SETTER -- (void)setRightType:(RightNavType)rightType{ - _rightType = rightType; -} +// setRightType: 与自动合成的 setter 完全相同,无需 override,保留注释备查 +//- (void)setRightType:(RightNavType)rightType{ +// _rightType = rightType; +//} - (void)setWebUrl:(NSString *)webUrl{ _webUrl = webUrl; diff --git a/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomePageV2HeardView.m b/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomePageV2HeardView.m index eb71a3f..eac2bdf 100644 --- a/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomePageV2HeardView.m +++ b/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomePageV2HeardView.m @@ -310,16 +310,16 @@ }; MJWeakSelf - self.watchDataView.tabSelectBlock = ^(NSInteger index, NSString *title) { - // tab 0 完整高度,其他收缩(header 40 + tab 52 + 内容区 68 = 160) - CGFloat height = (index == 0) ? 250 : 160; - [weakSelf.watchDataView mas_updateConstraints:^(MASConstraintMaker *make) { - make.height.mas_equalTo(height); - }]; - [UIView animateWithDuration:0.25 animations:^{ - [weakSelf layoutIfNeeded]; - }]; - }; +// self.watchDataView.tabSelectBlock = ^(NSInteger index, NSString *title) { +// // tab 0 完整高度,其他收缩(header 40 + tab 52 + 内容区 68 = 160) +// CGFloat height = (index == 0) ? 250 : 250; +// [weakSelf.watchDataView mas_updateConstraints:^(MASConstraintMaker *make) { +// make.height.mas_equalTo(height); +// }]; +// [UIView animateWithDuration:0.25 animations:^{ +// [weakSelf layoutIfNeeded]; +// }]; +// }; self.watchDataView.watchMoreBlock = ^{ if ([self.homeTopDelegate respondsToSelector:@selector(watchDetailClick)]) { [self.homeTopDelegate watchDetailClick]; diff --git a/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomeWatchDataView.m b/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomeWatchDataView.m index 0922fd4..5fe724e 100644 --- a/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomeWatchDataView.m +++ b/XinjiangProject/XinjiangProject/Project/HomeV2/View/XJHomeWatchDataView.m @@ -284,7 +284,7 @@ weekLabel; if ([HQCommonUtils isLogin]) { // 已登录,等待数据回调 } else { - _emptyLabel.text = @"~ 暂未登录 ~"; + _emptyLabel.text = @" 暂未登录 "; _emptyLabel.hidden = NO; _tabScrollView.hidden = false; _collectionView.hidden = false; @@ -449,7 +449,7 @@ weekLabel; _dataList = [dataList copy]; if (![HQCommonUtils isLogin]) { - _emptyLabel.text = @"~ 暂未登录 ~"; + _emptyLabel.text = @" 暂未登录 "; _emptyLabel.hidden = NO; _collectionView.hidden = YES; _tabScrollView.hidden = YES; @@ -529,7 +529,7 @@ weekLabel; - (void)p_startAutoScroll { [self p_stopAutoScroll]; if (_dataList.count <= 1) return; - _autoScrollTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 + _autoScrollTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(p_autoScrollToNext) userInfo:nil diff --git a/XinjiangProject/XinjiangProject/Project/HomeV2/XJHomePageV2ViewController.m b/XinjiangProject/XinjiangProject/Project/HomeV2/XJHomePageV2ViewController.m index ea9ea24..1d913c4 100644 --- a/XinjiangProject/XinjiangProject/Project/HomeV2/XJHomePageV2ViewController.m +++ b/XinjiangProject/XinjiangProject/Project/HomeV2/XJHomePageV2ViewController.m @@ -556,7 +556,6 @@ static CGFloat const kEmptyTableMinHeight = 250; // 或屏幕高度的一半 } - //banner图 if ([tag isEqualToString:@"LIST"]) { //请求成功 yes 继续轮询 DLog(@"轮询111---%@",response); @@ -585,7 +584,10 @@ static CGFloat const kEmptyTableMinHeight = 250; // 或屏幕高度的一半 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(120 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [weakSelf getMessageListData]; + if ([HQCommonUtils isLogin]) { + //请求消息列表 + [weakSelf getMessageListData]; + } }); } if ([tag isEqualToString:@"WEARWATCH"]) { diff --git a/XinjiangProject/XinjiangProject/Project/Qusetion/Controller/QuestionViewController.m b/XinjiangProject/XinjiangProject/Project/Qusetion/Controller/QuestionViewController.m index 80291f7..3e89b53 100644 --- a/XinjiangProject/XinjiangProject/Project/Qusetion/Controller/QuestionViewController.m +++ b/XinjiangProject/XinjiangProject/Project/Qusetion/Controller/QuestionViewController.m @@ -342,9 +342,7 @@ static CGFloat const kEmptyTableMinHeight = 300; // 或屏幕高度的一半 [self getData]; } - - - + } if ([tag isEqualToString:@"IMAPI"]) { @@ -476,7 +474,11 @@ static CGFloat const kEmptyTableMinHeight = 300; // 或屏幕高度的一半 - (void)foundQuestionAction { - + if (![HQCommonUtils isLogin]) { + + KPostNotification(KNotificationLoginStateChange, @NO); + return; + } RoomDoctorRecordsVC * foundVC = [[RoomDoctorRecordsVC alloc] init]; [self.navigationController pushViewController:foundVC animated:true]; @@ -484,6 +486,12 @@ static CGFloat const kEmptyTableMinHeight = 300; // 或屏幕高度的一半 - (void)smallQuestionAction { + if (![HQCommonUtils isLogin]) { + + KPostNotification(KNotificationLoginStateChange, @NO); + return; + } + if ([ESCTUIManager TUIUserStatus] == false) { [self loginImAccount]; @@ -503,7 +511,11 @@ static CGFloat const kEmptyTableMinHeight = 300; // 或屏幕高度的一半 - (void)myQuestionAction { - + if (![HQCommonUtils isLogin]) { + + KPostNotification(KNotificationLoginStateChange, @NO); + return; + } XJQustionRecordViewController * myVC = [[XJQustionRecordViewController alloc] init]; [self.navigationController pushViewController:myVC animated:true]; diff --git a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/Contents.json b/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/Contents.json index 541c844..bb831cb 100644 --- a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/Contents.json +++ b/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/Contents.json @@ -1,17 +1,15 @@ { "images" : [ { - "filename" : "homePageHeardTop.png", "idiom" : "universal", "scale" : "1x" }, { - "filename" : "homePageHeardTop@2x.png", + "filename" : "组 7.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "homePageHeardTop@3x.png", "idiom" : "universal", "scale" : "3x" } diff --git a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop.png b/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop.png deleted file mode 100644 index 81a6d47..0000000 Binary files a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop.png and /dev/null differ diff --git a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop@2x.png b/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop@2x.png deleted file mode 100644 index 133ff59..0000000 Binary files a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop@2x.png and /dev/null differ diff --git a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop@3x.png b/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop@3x.png deleted file mode 100644 index 8ef0ed4..0000000 Binary files a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/homePageHeardTop@3x.png and /dev/null differ diff --git a/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/组 7.png b/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/组 7.png new file mode 100644 index 0000000..1d69f5c Binary files /dev/null and b/XinjiangProject/XinjiangProject/Supporting Files/Assets.xcassets/HOMEV2/homePageHeardTop.imageset/组 7.png differ