|
@@ -30,6 +30,7 @@
|
|
|
#import "KSMediaManager.h"
|
|
|
#import "KSUMShareManager.h"
|
|
|
#import "UserInfoManager.h"
|
|
|
+#import "KSWebLoadRefreshView.h"
|
|
|
|
|
|
typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
CHOOSETYPE_XML,
|
|
@@ -65,6 +66,8 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
|
|
|
@property (nonatomic, assign) BOOL isFirstLoad;
|
|
|
|
|
|
+@property (nonatomic, strong) KSWebLoadRefreshView *errorView;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation KSBaseWKWebViewController
|
|
@@ -82,9 +85,22 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
|
|
|
|
|
|
- (void)captureViewTips:(NSNotification *)notification {
|
|
|
- if ([UIScreen mainScreen].isCaptured) {
|
|
|
- [self didCapturedView];
|
|
|
+ [self checkCaptured];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)checkCaptured {
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ if ([self checkIsCaptured]) {
|
|
|
+ [self didCapturedView];
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+#pragma mark ---- 镜像和投屏检测
|
|
|
+- (BOOL)checkIsCaptured {
|
|
|
+ if ([UIScreen mainScreen].isCaptured && [UIScreen screens].count < 2) {
|
|
|
+ return YES;
|
|
|
}
|
|
|
+ return NO;
|
|
|
}
|
|
|
|
|
|
- (void)didCapturedView {
|
|
@@ -95,12 +111,11 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
[content setValue:@"pause" forKey:@"status"];
|
|
|
[sendParm setValue:content forKey:@"content"];
|
|
|
[self postMessage:sendParm];
|
|
|
-
|
|
|
-// [LOADING_MANAGER MBShowAUTOHidingInWindow:@"为了保证数据安全,请不要录屏"];
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
- (void)operationDealCallbackMessage:(NSNotification *)notification {
|
|
|
NSString *status = [notification object];
|
|
|
NSMutableDictionary *sendParm = [NSMutableDictionary dictionary];
|
|
@@ -120,15 +135,11 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
NSInteger orientation = [parmDic ks_integerValueForKey:@"orientation"];
|
|
|
|
|
|
BOOL isLandScape = orientation == 0 ? YES : NO;
|
|
|
- if (_landScape != isLandScape) {
|
|
|
- [self changeOrientation:isLandScape];
|
|
|
- }
|
|
|
- // 是否隐藏头部导航条
|
|
|
- self.hideTop = [parmDic ks_boolValueForKey:@"isHideTitle"];
|
|
|
+ self.ks_landScape = isLandScape;
|
|
|
+ [self changeOrientation:isLandScape];
|
|
|
}
|
|
|
|
|
|
- (void)changeOrientation:(BOOL)isLandScape {
|
|
|
- self.landScape = isLandScape;
|
|
|
if (isLandScape) {
|
|
|
// 切换到横屏
|
|
|
AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
|
|
@@ -167,52 +178,36 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
[super viewWillDisappear:animated];
|
|
|
- if (_hasChangeSource && self.keepOrientation == NO && self.landScape == YES) {
|
|
|
- [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
|
|
- [self changeOrientation:NO];
|
|
|
+ BOOL isBack = [self isViewPopDismiss];
|
|
|
+ if (isBack) {
|
|
|
+ if (self.preCtrl) {
|
|
|
+ if (self.ks_landScape != self.preCtrl.ks_landScape) {
|
|
|
+ [self changeOrientation:self.preCtrl.ks_landScape];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (![self.preCtrl isKindOfClass:[KSBaseWKWebViewController class]]) {
|
|
|
+ [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ KSBaseViewController *nextCtrl = [self getNextViewController];
|
|
|
+ if (nextCtrl) {
|
|
|
+ if (nextCtrl.ks_landScape != self.ks_landScape) {
|
|
|
+ [self changeOrientation:NO];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- self.keepOrientation = NO;
|
|
|
}
|
|
|
|
|
|
- (void)initWebView {
|
|
|
[self.scrollView removeFromSuperview];
|
|
|
- [self.view addSubview:self.navView];
|
|
|
- CGFloat topHeight = kNaviBarHeight;
|
|
|
- if (self.hideTop) {
|
|
|
- topHeight = 0.0f;
|
|
|
- }
|
|
|
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.left.right.top.mas_equalTo(self.view);
|
|
|
- make.height.mas_equalTo(topHeight);
|
|
|
- }];
|
|
|
-
|
|
|
- [self.view addSubview:self.webBackButton];
|
|
|
- [self.webBackButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
- make.left.top.mas_equalTo(self.view);
|
|
|
- make.height.mas_equalTo(kNaviBarHeight);
|
|
|
- make.width.mas_equalTo(44);
|
|
|
- }];
|
|
|
- if (self.hideTop) {
|
|
|
- self.webBackButton.hidden = YES;
|
|
|
- }
|
|
|
- if (_hiddenNavBar) {
|
|
|
- topHeight = 0.0f;
|
|
|
- }
|
|
|
- if (self.headTitle) {
|
|
|
- [self.navView.topTitleLabel setText:_headTitle];
|
|
|
- }
|
|
|
|
|
|
if (_myWebView == nil) {
|
|
|
|
|
|
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
|
|
|
config.selectionGranularity = WKSelectionGranularityDynamic;
|
|
|
config.allowsInlineMediaPlayback = YES;
|
|
|
- if (@available(iOS 10.0, *)) {
|
|
|
- config.mediaTypesRequiringUserActionForPlayback = NO;
|
|
|
- } else {
|
|
|
- // Fallback on earlier versions
|
|
|
- config.requiresUserActionForMediaPlayback = NO;
|
|
|
- }
|
|
|
+ config.mediaTypesRequiringUserActionForPlayback = NO;
|
|
|
config.processPool = [KSBaseWKWebViewController singleWkProcessPool];
|
|
|
config.websiteDataStore = [WKWebsiteDataStore defaultDataStore];
|
|
|
[self configUserAgent:config];
|
|
@@ -238,12 +233,11 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
_myWebView.scrollView.showsHorizontalScrollIndicator = NO;
|
|
|
// 加载进度条和title
|
|
|
[_myWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
|
|
|
- [_myWebView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
|
|
|
|
|
|
[self.view addSubview:_myWebView];
|
|
|
[_myWebView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
make.left.right.mas_equalTo(self.view);
|
|
|
- make.top.mas_equalTo(self.view.mas_top).offset(topHeight);
|
|
|
+ make.top.mas_equalTo(self.view.mas_top);
|
|
|
make.bottom.mas_equalTo(self.view.mas_bottom);
|
|
|
}];
|
|
|
if (@available(iOS 11.0, *)) {
|
|
@@ -254,9 +248,6 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
[self setupProgress];
|
|
|
// 修改userAgent
|
|
|
[self loadRequest];
|
|
|
-
|
|
|
- [self.view bringSubviewToFront:self.navView];
|
|
|
- [self.view bringSubviewToFront:self.webBackButton];
|
|
|
}
|
|
|
else {
|
|
|
[_myWebView reload];
|
|
@@ -330,8 +321,12 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
|
|
|
- (void)handleScriptMessageSource:(NSDictionary *)parm {
|
|
|
if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"back"]) { // 返回
|
|
|
+ [self.myWebView stopLoading];
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
}
|
|
|
+ else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"goBack"]) { // 逐级返回
|
|
|
+ [self backAction];
|
|
|
+ }
|
|
|
else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"login"]) {
|
|
|
// 回到登录页面
|
|
|
[self backLoginView];
|
|
@@ -356,7 +351,9 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
// 横竖屏
|
|
|
NSInteger orientation = [valueDic ks_integerValueForKey:@"orientation"];
|
|
|
BOOL isLandScape = orientation == 0 ? YES : NO;
|
|
|
+ self.ks_landScape = isLandScape;
|
|
|
[self changeOrientation:isLandScape];
|
|
|
+
|
|
|
}
|
|
|
else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"keepScreenLongLight"]) {
|
|
|
NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
|
|
@@ -405,13 +402,9 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
KSAccompanyWebViewController *detailCtrl = [[KSAccompanyWebViewController alloc] init];
|
|
|
detailCtrl.url = [valueDic ks_stringValueForKey:@"url"];
|
|
|
detailCtrl.parmDic = valueDic;
|
|
|
- detailCtrl.hiddenNavBar = [valueDic ks_boolValueForKey:@"isHideTitle"];
|
|
|
NSInteger orientation = [valueDic ks_integerValueForKey:@"orientation"];
|
|
|
BOOL isLandScape = orientation == 0 ? YES : NO;
|
|
|
- if (isLandScape == self.landScape) {
|
|
|
- self.keepOrientation = YES;
|
|
|
- detailCtrl.keepOrientation = YES;
|
|
|
- }
|
|
|
+ detailCtrl.ks_landScape = isLandScape;
|
|
|
[self postMessage:parm];
|
|
|
[self.navigationController pushViewController:detailCtrl animated:YES];
|
|
|
}
|
|
@@ -446,6 +439,7 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
[self postMessage:parm];
|
|
|
}
|
|
|
else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"backIconChange"]) {
|
|
|
+ /*
|
|
|
NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
|
|
|
NSString *backColor = [valueDic ks_stringValueForKey:@"iconStyle"];
|
|
|
NSString *backImage = @"";
|
|
@@ -459,8 +453,10 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
// 是否隐藏按钮
|
|
|
BOOL hideButton = [valueDic ks_boolValueForKey:@"backIconHide"];
|
|
|
self.webBackButton.hidden = hideButton;
|
|
|
+ */
|
|
|
}
|
|
|
else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"setBarStatus"]) { // 顶部是否隐藏
|
|
|
+ /*
|
|
|
NSDictionary *valueDic = [parm ks_dictionaryValueForKey:@"content"];
|
|
|
BOOL isShow = [valueDic ks_boolValueForKey:@"status"]; // 0 隐藏 1 显示
|
|
|
self.hiddenNavBar = !isShow;
|
|
@@ -472,6 +468,7 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
[self.myWebView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
make.top.mas_equalTo(self.view.mas_top).offset(navHeight);
|
|
|
}];
|
|
|
+ */
|
|
|
}
|
|
|
else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"paymentOrder"]) {
|
|
|
NSDictionary *content = [parm ks_dictionaryValueForKey:@"content"];
|
|
@@ -725,11 +722,7 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
}
|
|
|
|
|
|
- (void)openSettingView {
|
|
|
- if (@available(iOS 10, *)) {
|
|
|
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
|
|
|
- } else {
|
|
|
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
|
|
|
- }
|
|
|
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
|
|
|
}
|
|
|
|
|
|
- (void)displaySource:(NSURL *)localUrl {
|
|
@@ -865,6 +858,7 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
// 6 页面加载失败时调用
|
|
|
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation {
|
|
|
NSLog(@"6-------页面加载失败时调用");
|
|
|
+ [self showErrorView];
|
|
|
}
|
|
|
|
|
|
// 接收到服务器跳转请求之后调用
|
|
@@ -955,12 +949,6 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
self.progressLayer.frame = CGRectMake(0, 0, 0, 3);
|
|
|
});
|
|
|
}
|
|
|
- }else if ([keyPath isEqualToString:@"title"]) {
|
|
|
- // 顶部title
|
|
|
- self.headTitle = change[@"new"];
|
|
|
- if (self.hiddenNavBar == NO) {
|
|
|
- self.navView.topTitleLabel.text = self.headTitle;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1021,41 +1009,10 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
-- (void)setHiddenNavBar:(BOOL)hiddenNavBar {
|
|
|
- _hiddenNavBar = hiddenNavBar;
|
|
|
- if (hiddenNavBar) {
|
|
|
- self.navView.topTitleLabel.text = @"";
|
|
|
- }
|
|
|
- else {
|
|
|
- self.navView.topTitleLabel.text = self.headTitle;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark --- lazying
|
|
|
-- (KSWebNavView *)navView {
|
|
|
- if (!_navView) {
|
|
|
- _navView = [[KSWebNavView alloc] init];
|
|
|
-
|
|
|
- }
|
|
|
- return _navView;
|
|
|
-}
|
|
|
-
|
|
|
-- (KSWebBackButton *)webBackButton {
|
|
|
- if (!_webBackButton) {
|
|
|
- _webBackButton = [[KSWebBackButton alloc] init];
|
|
|
- MJWeakSelf;
|
|
|
- [_webBackButton webViewBackAction:^{
|
|
|
- [weakSelf backAction];
|
|
|
- }];
|
|
|
- }
|
|
|
- return _webBackButton;
|
|
|
-}
|
|
|
-
|
|
|
- (void)dealloc {
|
|
|
NSLog(@"webView dealloc -----");
|
|
|
[[_myWebView configuration].userContentController removeScriptMessageHandlerForName:@"COLEXIU"];
|
|
|
[_myWebView removeObserver:self forKeyPath:@"estimatedProgress"];
|
|
|
- [_myWebView removeObserver:self forKeyPath:@"title"];
|
|
|
[_myWebView loadHTMLString:@"" baseURL:nil];
|
|
|
[_myWebView removeFromSuperview];
|
|
|
_myWebView = nil;
|
|
@@ -1333,6 +1290,38 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
|
|
|
}
|
|
|
return filesize;
|
|
|
}
|
|
|
+
|
|
|
+- (KSWebLoadRefreshView *)errorView {
|
|
|
+ if (!_errorView) {
|
|
|
+ _errorView = [KSWebLoadRefreshView shareInstance];
|
|
|
+ MJWeakSelf;
|
|
|
+ [_errorView failViewActionCallback:^(BOOL isBack) {
|
|
|
+ [weakSelf hideErrorView];
|
|
|
+ if (isBack) {
|
|
|
+ [weakSelf backAction];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [weakSelf loadRequest];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return _errorView;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)showErrorView {
|
|
|
+ if (![self.view.subviews containsObject:self.errorView]) {
|
|
|
+ [self.view addSubview:self.errorView];
|
|
|
+ [self.errorView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.top.bottom.mas_equalTo(self.view);
|
|
|
+ }];
|
|
|
+ [self.view bringSubviewToFront:self.errorView];
|
|
|
+ }
|
|
|
+}
|
|
|
+- (void)hideErrorView {
|
|
|
+ if ([self.view.subviews containsObject:self.errorView]) {
|
|
|
+ [self.errorView removeFromSuperview];
|
|
|
+ }
|
|
|
+}
|
|
|
/*
|
|
|
#pragma mark - Navigation
|
|
|
|