|
@@ -1,23 +1,23 @@
|
|
|
//
|
|
|
-// JYNewWebController.m
|
|
|
+// JYWKNewWebController.m
|
|
|
// JianYuIOS
|
|
|
//
|
|
|
-// Created by apple on 2020/6/11.
|
|
|
+// Created by apple on 2020/8/24.
|
|
|
// Copyright © 2020 lixianglan. All rights reserved.
|
|
|
//
|
|
|
|
|
|
-#import "JYNewWebController.h"
|
|
|
+#import "JYWKNewWebController.h"
|
|
|
#import <WebKit/WebKit.h>
|
|
|
|
|
|
-@interface JYNewWebController ()<WKNavigationDelegate,UIWebViewDelegate>
|
|
|
+@interface JYWKNewWebController ()<WKNavigationDelegate>
|
|
|
+@property (nonatomic, strong) UIProgressView *progressView;
|
|
|
+@property (nonatomic, strong) WKWebView *webView;
|
|
|
|
|
|
|
|
|
-@property (nonatomic, strong) UIProgressView *progressView;
|
|
|
-//@property (nonatomic, strong) WKWebView *webView;
|
|
|
-@property (nonatomic, strong) UIWebView *webView;
|
|
|
@end
|
|
|
|
|
|
-@implementation JYNewWebController
|
|
|
+@implementation JYWKNewWebController
|
|
|
+
|
|
|
|
|
|
-(void)viewWillAppear:(BOOL)animated
|
|
|
{
|
|
@@ -29,7 +29,7 @@
|
|
|
{
|
|
|
if (_progressView == nil) {
|
|
|
CGFloat H = 0.0;
|
|
|
- if (self.titleShow) {
|
|
|
+ if (self.titleShow ) {
|
|
|
if ([self.titleShow isEqualToString:@"-1"]) {
|
|
|
|
|
|
}else {
|
|
@@ -103,24 +103,26 @@
|
|
|
backBtn_1.hidden = NO;
|
|
|
}
|
|
|
|
|
|
- self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, H, WIDTH, HEIGHT-STATUS_BAR_HEIGHT-H)];
|
|
|
+
|
|
|
+ WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
|
|
|
+ config.preferences = [[WKPreferences alloc] init];
|
|
|
+ config.preferences.minimumFontSize = 0;
|
|
|
+ config.allowsInlineMediaPlayback = YES;
|
|
|
+ self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, H, WIDTH, HEIGHT-STATUS_BAR_HEIGHT-H) configuration:config];
|
|
|
if (iPhoneX) {
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
- self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
+ _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
}
|
|
|
}
|
|
|
self.webView.scrollView.bounces = NO;
|
|
|
- _webView.scrollView.bounces = NO;
|
|
|
-
|
|
|
- _webView.delegate = self;
|
|
|
- _webView.userInteractionEnabled = YES;
|
|
|
- [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
|
|
|
+ self.webView.navigationDelegate = self;
|
|
|
+ self.webView.userInteractionEnabled = YES;
|
|
|
[self.view addSubview:self.webView];
|
|
|
+ [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
|
|
|
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
|
|
|
[self.view addSubview:backBtn_1];
|
|
|
[self.view addSubview:titleView];
|
|
|
}
|
|
|
-
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
// Do any additional setup after loading the view.
|
|
@@ -129,74 +131,70 @@
|
|
|
NSLog(@"title:%@",self.titleShow);
|
|
|
NSLog(@"url:%@",self.url);
|
|
|
[self initUI];//渲染页面
|
|
|
-// [self.view addSubview:self.progressView];
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSelf) name:@"kNewWebControllerDismiss" object:nil];
|
|
|
+ [self.view addSubview:self.progressView];
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-#pragma mark - UIWebViewDelegate
|
|
|
-- (void)webViewDidStartLoad:(UIWebView *)webView {
|
|
|
-// [[LXViewControllerManager shareViewControllerManager] showHudText:@""];
|
|
|
+
|
|
|
+
|
|
|
+#pragma mark - WKNavigationDelegate
|
|
|
+/* 页面加载完成 */
|
|
|
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
|
|
|
+
|
|
|
+// NSLog(@"-----页面加载完成%@",webView.URL.absoluteString);
|
|
|
+ [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
|
|
|
}
|
|
|
-- (void)webViewDidFinishLoad:(UIWebView *)webView{
|
|
|
- [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
- [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
|
|
|
- // Disable callout
|
|
|
- [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
|
|
|
+
|
|
|
+// 页面开始加载时调用
|
|
|
+- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
|
|
|
+
|
|
|
+}
|
|
|
+// 当内容开始返回时调用
|
|
|
+- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
|
|
|
}
|
|
|
|
|
|
--(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
|
|
|
-// [[LXViewControllerManager shareViewControllerManager] hideHud];
|
|
|
+// 页面加载失败时调用
|
|
|
+- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(nonnull NSError *)error{
|
|
|
[[GlobalData shareInstance] addOnePlistData:@{
|
|
|
- @"detail":[[self.webView stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\n%@",[error description]]],
|
|
|
+ @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\n%@",[error description]]],
|
|
|
@"reqTime":[NSNumber numberWithInt:0],
|
|
|
}];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
-#pragma mark - WKNavigationDelegate
|
|
|
-/* 页面加载完成 */
|
|
|
-//- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
|
|
|
-//
|
|
|
-// [self.webView evaluateJavaScript:@"document.documentElement.style.webkitTouchCallout='none';" completionHandler:nil];
|
|
|
-// [self.webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';"completionHandler:nil];
|
|
|
-//}
|
|
|
-//// 页面开始加载时调用
|
|
|
-//- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
|
|
|
-//
|
|
|
-//}
|
|
|
-//// 当内容开始返回时调用
|
|
|
-//- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
|
|
|
-//}
|
|
|
-//
|
|
|
-//// 页面加载失败时调用
|
|
|
-//- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(nonnull NSError *)error{
|
|
|
-// [[GlobalData shareInstance] addOnePlistData:@{
|
|
|
-// @"detail":[[self stringByEvaluatingJavaScriptFromString:@"document.location.href"] stringByAppendingString:[NSString stringWithFormat:@"\n%@",[error description]]],
|
|
|
-// @"reqTime":[NSNumber numberWithInt:0],
|
|
|
-// }];
|
|
|
-//}
|
|
|
-//- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
|
|
|
-//{
|
|
|
-// __block NSString *resultString = nil;
|
|
|
-// __block BOOL finished = NO;
|
|
|
-//
|
|
|
-// [self.webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
|
|
|
-// if (error == nil) {
|
|
|
-// if (result != nil) {
|
|
|
-// resultString = [NSString stringWithFormat:@"%@", result];
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
|
|
|
-// }
|
|
|
-// finished = YES;
|
|
|
-// }];
|
|
|
-//
|
|
|
-// while (!finished) {
|
|
|
-// [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
|
|
|
-// }
|
|
|
-// return resultString;
|
|
|
-//}
|
|
|
+-(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
|
|
|
+{
|
|
|
+ //如果是跳转一个新页面
|
|
|
+ if (navigationAction.targetFrame == nil) {
|
|
|
+ [webView loadRequest:navigationAction.request];
|
|
|
+ }
|
|
|
+
|
|
|
+ decisionHandler(WKNavigationActionPolicyAllow);
|
|
|
+}
|
|
|
+
|
|
|
+- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
|
|
|
+{
|
|
|
+ __block NSString *resultString = nil;
|
|
|
+ __block BOOL finished = NO;
|
|
|
+
|
|
|
+ [self.webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
|
|
|
+ if (error == nil) {
|
|
|
+ if (result != nil) {
|
|
|
+ resultString = [NSString stringWithFormat:@"%@", result];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ NSLog(@"evaluateJavaScript error : %@", error.localizedDescription);
|
|
|
+ }
|
|
|
+ finished = YES;
|
|
|
+ }];
|
|
|
+
|
|
|
+ while (!finished) {
|
|
|
+ [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
|
|
|
+ }
|
|
|
+ return resultString;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -232,7 +230,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
/*
|
|
|
#pragma mark - Navigation
|
|
|
|