首页监测自测修改
This commit is contained in:
@@ -84,8 +84,8 @@
|
|||||||
// 最新地址
|
// 最新地址
|
||||||
//#define Http @"http://192.168.1.47"//王昊
|
//#define Http @"http://192.168.1.47"//王昊
|
||||||
|
|
||||||
//#define Http @"https://xj-api.mcrm.vip:8888"//
|
#define Http @"https://xj-api.mcrm.vip:8888"//
|
||||||
#define Http @"http://192.168.1.47"//王昊
|
//#define Http @"http://192.168.1.47"//王昊
|
||||||
#define H5DevHost @"xj-api.mcrm.vip:8888"//
|
#define H5DevHost @"xj-api.mcrm.vip:8888"//
|
||||||
#define IntervenH5 @"https://xj-admin.mcrm.vip:8888"
|
#define IntervenH5 @"https://xj-admin.mcrm.vip:8888"
|
||||||
#define SCHEME @"https" //
|
#define SCHEME @"https" //
|
||||||
|
|||||||
@@ -9,13 +9,37 @@
|
|||||||
|
|
||||||
@interface XJBaseWebViewVC ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
|
@interface XJBaseWebViewVC ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
|
||||||
|
|
||||||
@property (nonatomic, strong)NSURL *originalUrl;
|
// 以下三个属性声明后未使用,暂时保留
|
||||||
@property (nonatomic, copy)NSString *videoUrl;
|
//@property (nonatomic, strong)NSURL *originalUrl;
|
||||||
@property (nonatomic, copy)NSString *messageType;
|
//@property (nonatomic, copy)NSString *videoUrl;
|
||||||
|
//@property (nonatomic, copy)NSString *messageType;
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
// ── 弱引用代理 ──────────────────────────────────────────────────────────────
|
||||||
|
// WKUserContentController 对 addScriptMessageHandler 的 handler 是强引用。
|
||||||
|
// 如果直接传 self,self → wkWebView → configuration → userContentController → self,
|
||||||
|
// 形成循环引用,VC 永远无法释放。
|
||||||
|
// 解决方案:用一个弱引用中间对象转发消息。
|
||||||
|
@interface XJWeakScriptMessageHandler : NSObject <WKScriptMessageHandler>
|
||||||
|
@property (nonatomic, weak) id<WKScriptMessageHandler> delegate;
|
||||||
|
+ (instancetype)handlerWithDelegate:(id<WKScriptMessageHandler>)delegate;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation XJWeakScriptMessageHandler
|
||||||
|
+ (instancetype)handlerWithDelegate:(id<WKScriptMessageHandler>)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
|
@implementation XJBaseWebViewVC
|
||||||
|
|
||||||
|
|
||||||
@@ -36,6 +60,14 @@
|
|||||||
[self.navigationController popViewControllerAnimated:YES];
|
[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{
|
- (void)viewWillAppear:(BOOL)animated{
|
||||||
[super viewWillAppear:animated];
|
[super viewWillAppear:animated];
|
||||||
if (_wkWebView) {
|
if (_wkWebView) {
|
||||||
@@ -51,14 +83,14 @@
|
|||||||
[super viewWillDisappear:animated];
|
[super viewWillDisappear:animated];
|
||||||
_wkWebView.navigationDelegate = nil;
|
_wkWebView.navigationDelegate = nil;
|
||||||
_wkWebView.UIDelegate = nil;
|
_wkWebView.UIDelegate = nil;
|
||||||
//清除cookies
|
// ⚠️ 以下代码会清除整个 App 的所有 Cookie,影响其他模块登录状态,已注释
|
||||||
NSHTTPCookie *cookie;
|
// NSHTTPCookie *cookie;
|
||||||
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
|
// NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
|
||||||
for (cookie in [storage cookies]) {
|
// for (cookie in [storage cookies]) {
|
||||||
[storage deleteCookie:cookie];
|
// [storage deleteCookie:cookie];
|
||||||
}
|
// }
|
||||||
[[NSURLCache sharedURLCache] removeAllCachedResponses];
|
// [[NSURLCache sharedURLCache] removeAllCachedResponses];
|
||||||
[self clearWebViewCache];
|
// [self clearWebViewCache];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Create UI
|
#pragma mark - Create UI
|
||||||
@@ -69,18 +101,36 @@
|
|||||||
preferences.javaScriptCanOpenWindowsAutomatically = YES;
|
preferences.javaScriptCanOpenWindowsAutomatically = YES;
|
||||||
preferences.minimumFontSize = 10;
|
preferences.minimumFontSize = 10;
|
||||||
configuration.preferences = preferences;
|
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代码
|
//防止搜索框自动放大 注入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);";
|
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];
|
WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
|
||||||
WKUserContentController * wkUController = [[WKUserContentController alloc] init];
|
|
||||||
[wkUController addScriptMessageHandler: self name: @"finishActivity"];//不带参数的调用
|
|
||||||
|
|
||||||
[wkUController addUserScript:wkUScript];
|
// 原写法(已废弃):新建 wkUController 并覆盖 configuration.userContentController,
|
||||||
configuration.userContentController= wkUController;
|
// 导致上方注册的 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 = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, MyViewHEIGHT) configuration:configuration];
|
||||||
self.wkWebView.navigationDelegate = self;
|
self.wkWebView.navigationDelegate = self;
|
||||||
@@ -201,10 +251,13 @@
|
|||||||
|
|
||||||
#pragma mark - 自定义
|
#pragma mark - 自定义
|
||||||
- (void)onBackClicked{
|
- (void)onBackClicked{
|
||||||
if ( self.wkWebView.canGoBack){
|
if (self.wkWebView.canGoBack) {
|
||||||
[self.wkWebView goBack];
|
[self.wkWebView goBack];
|
||||||
} else {
|
} else {
|
||||||
|
// 原写法:只清缓存没有 pop,页面会卡住
|
||||||
|
// [self clearWebViewCache];
|
||||||
[self clearWebViewCache];
|
[self clearWebViewCache];
|
||||||
|
[self.navigationController popViewControllerAnimated:YES];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,19 +279,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
- (NSString *)URLEncodedString:(NSString *)urlString{
|
- (NSString *)URLEncodedString:(NSString *)urlString{
|
||||||
NSString *encodePath ;
|
NSString *encodePath;
|
||||||
if (!IOS7) {
|
|
||||||
encodePath = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
||||||
}else{
|
|
||||||
encodePath = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
encodePath = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
||||||
}return encodePath;
|
return encodePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - SETTER
|
#pragma mark - SETTER
|
||||||
- (void)setRightType:(RightNavType)rightType{
|
// setRightType: 与自动合成的 setter 完全相同,无需 override,保留注释备查
|
||||||
_rightType = rightType;
|
//- (void)setRightType:(RightNavType)rightType{
|
||||||
}
|
// _rightType = rightType;
|
||||||
|
//}
|
||||||
|
|
||||||
- (void)setWebUrl:(NSString *)webUrl{
|
- (void)setWebUrl:(NSString *)webUrl{
|
||||||
_webUrl = webUrl;
|
_webUrl = webUrl;
|
||||||
|
|||||||
@@ -310,16 +310,16 @@
|
|||||||
|
|
||||||
};
|
};
|
||||||
MJWeakSelf
|
MJWeakSelf
|
||||||
self.watchDataView.tabSelectBlock = ^(NSInteger index, NSString *title) {
|
// self.watchDataView.tabSelectBlock = ^(NSInteger index, NSString *title) {
|
||||||
// tab 0 完整高度,其他收缩(header 40 + tab 52 + 内容区 68 = 160)
|
// // tab 0 完整高度,其他收缩(header 40 + tab 52 + 内容区 68 = 160)
|
||||||
CGFloat height = (index == 0) ? 250 : 160;
|
// CGFloat height = (index == 0) ? 250 : 250;
|
||||||
[weakSelf.watchDataView mas_updateConstraints:^(MASConstraintMaker *make) {
|
// [weakSelf.watchDataView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||||
make.height.mas_equalTo(height);
|
// make.height.mas_equalTo(height);
|
||||||
}];
|
// }];
|
||||||
[UIView animateWithDuration:0.25 animations:^{
|
// [UIView animateWithDuration:0.25 animations:^{
|
||||||
[weakSelf layoutIfNeeded];
|
// [weakSelf layoutIfNeeded];
|
||||||
}];
|
// }];
|
||||||
};
|
// };
|
||||||
self.watchDataView.watchMoreBlock = ^{
|
self.watchDataView.watchMoreBlock = ^{
|
||||||
if ([self.homeTopDelegate respondsToSelector:@selector(watchDetailClick)]) {
|
if ([self.homeTopDelegate respondsToSelector:@selector(watchDetailClick)]) {
|
||||||
[self.homeTopDelegate watchDetailClick];
|
[self.homeTopDelegate watchDetailClick];
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ weekLabel;
|
|||||||
if ([HQCommonUtils isLogin]) {
|
if ([HQCommonUtils isLogin]) {
|
||||||
// 已登录,等待数据回调
|
// 已登录,等待数据回调
|
||||||
} else {
|
} else {
|
||||||
_emptyLabel.text = @"~ 暂未登录 ~";
|
_emptyLabel.text = @" 暂未登录 ";
|
||||||
_emptyLabel.hidden = NO;
|
_emptyLabel.hidden = NO;
|
||||||
_tabScrollView.hidden = false;
|
_tabScrollView.hidden = false;
|
||||||
_collectionView.hidden = false;
|
_collectionView.hidden = false;
|
||||||
@@ -449,7 +449,7 @@ weekLabel;
|
|||||||
_dataList = [dataList copy];
|
_dataList = [dataList copy];
|
||||||
|
|
||||||
if (![HQCommonUtils isLogin]) {
|
if (![HQCommonUtils isLogin]) {
|
||||||
_emptyLabel.text = @"~ 暂未登录 ~";
|
_emptyLabel.text = @" 暂未登录 ";
|
||||||
_emptyLabel.hidden = NO;
|
_emptyLabel.hidden = NO;
|
||||||
_collectionView.hidden = YES;
|
_collectionView.hidden = YES;
|
||||||
_tabScrollView.hidden = YES;
|
_tabScrollView.hidden = YES;
|
||||||
@@ -529,7 +529,7 @@ weekLabel;
|
|||||||
- (void)p_startAutoScroll {
|
- (void)p_startAutoScroll {
|
||||||
[self p_stopAutoScroll];
|
[self p_stopAutoScroll];
|
||||||
if (_dataList.count <= 1) return;
|
if (_dataList.count <= 1) return;
|
||||||
_autoScrollTimer = [NSTimer scheduledTimerWithTimeInterval:3.0
|
_autoScrollTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
|
||||||
target:self
|
target:self
|
||||||
selector:@selector(p_autoScrollToNext)
|
selector:@selector(p_autoScrollToNext)
|
||||||
userInfo:nil
|
userInfo:nil
|
||||||
|
|||||||
@@ -556,7 +556,6 @@ static CGFloat const kEmptyTableMinHeight = 250; // 或屏幕高度的一半
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//banner图
|
|
||||||
if ([tag isEqualToString:@"LIST"]) {
|
if ([tag isEqualToString:@"LIST"]) {
|
||||||
//请求成功 yes 继续轮询
|
//请求成功 yes 继续轮询
|
||||||
DLog(@"轮询111---%@",response);
|
DLog(@"轮询111---%@",response);
|
||||||
@@ -585,7 +584,10 @@ static CGFloat const kEmptyTableMinHeight = 250; // 或屏幕高度的一半
|
|||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
|
||||||
(int64_t)(120 * NSEC_PER_SEC)),
|
(int64_t)(120 * NSEC_PER_SEC)),
|
||||||
dispatch_get_main_queue(), ^{
|
dispatch_get_main_queue(), ^{
|
||||||
|
if ([HQCommonUtils isLogin]) {
|
||||||
|
//请求消息列表
|
||||||
[weakSelf getMessageListData];
|
[weakSelf getMessageListData];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if ([tag isEqualToString:@"WEARWATCH"]) {
|
if ([tag isEqualToString:@"WEARWATCH"]) {
|
||||||
|
|||||||
+14
-2
@@ -343,8 +343,6 @@ static CGFloat const kEmptyTableMinHeight = 300; // 或屏幕高度的一半
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([tag isEqualToString:@"IMAPI"]) {
|
if ([tag isEqualToString:@"IMAPI"]) {
|
||||||
@@ -476,7 +474,11 @@ static CGFloat const kEmptyTableMinHeight = 300; // 或屏幕高度的一半
|
|||||||
|
|
||||||
- (void)foundQuestionAction {
|
- (void)foundQuestionAction {
|
||||||
|
|
||||||
|
if (![HQCommonUtils isLogin]) {
|
||||||
|
|
||||||
|
KPostNotification(KNotificationLoginStateChange, @NO);
|
||||||
|
return;
|
||||||
|
}
|
||||||
RoomDoctorRecordsVC * foundVC = [[RoomDoctorRecordsVC alloc] init];
|
RoomDoctorRecordsVC * foundVC = [[RoomDoctorRecordsVC alloc] init];
|
||||||
|
|
||||||
[self.navigationController pushViewController:foundVC animated:true];
|
[self.navigationController pushViewController:foundVC animated:true];
|
||||||
@@ -484,6 +486,12 @@ static CGFloat const kEmptyTableMinHeight = 300; // 或屏幕高度的一半
|
|||||||
|
|
||||||
- (void)smallQuestionAction {
|
- (void)smallQuestionAction {
|
||||||
|
|
||||||
|
if (![HQCommonUtils isLogin]) {
|
||||||
|
|
||||||
|
KPostNotification(KNotificationLoginStateChange, @NO);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ([ESCTUIManager TUIUserStatus] == false) {
|
if ([ESCTUIManager TUIUserStatus] == false) {
|
||||||
|
|
||||||
[self loginImAccount];
|
[self loginImAccount];
|
||||||
@@ -503,7 +511,11 @@ static CGFloat const kEmptyTableMinHeight = 300; // 或屏幕高度的一半
|
|||||||
|
|
||||||
- (void)myQuestionAction {
|
- (void)myQuestionAction {
|
||||||
|
|
||||||
|
if (![HQCommonUtils isLogin]) {
|
||||||
|
|
||||||
|
KPostNotification(KNotificationLoginStateChange, @NO);
|
||||||
|
return;
|
||||||
|
}
|
||||||
XJQustionRecordViewController * myVC = [[XJQustionRecordViewController alloc] init];
|
XJQustionRecordViewController * myVC = [[XJQustionRecordViewController alloc] init];
|
||||||
|
|
||||||
[self.navigationController pushViewController:myVC animated:true];
|
[self.navigationController pushViewController:myVC animated:true];
|
||||||
|
|||||||
+1
-3
@@ -1,17 +1,15 @@
|
|||||||
{
|
{
|
||||||
"images" : [
|
"images" : [
|
||||||
{
|
{
|
||||||
"filename" : "homePageHeardTop.png",
|
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "1x"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "homePageHeardTop@2x.png",
|
"filename" : "组 7.png",
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename" : "homePageHeardTop@3x.png",
|
|
||||||
"idiom" : "universal",
|
"idiom" : "universal",
|
||||||
"scale" : "3x"
|
"scale" : "3x"
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 45 KiB |
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 105 KiB |
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 243 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 83 KiB |
Reference in New Issue
Block a user