Commit d5dba53b4b97b4c99835bf0af5aa4fd1e48e6ba7

Authored by 张旭
2 parents af9ea1a3 4d6ac41d

Merge branch 'master' of bj.gitlab.cnlive.com:ios-team/ScioLive

CNLiveScioLive/Pages/Base/CNLiveWebViewController.h
@@ -11,5 +11,6 @@ @@ -11,5 +11,6 @@
11 @interface CNLiveWebViewController : CNLiveBaseViewController 11 @interface CNLiveWebViewController : CNLiveBaseViewController
12 @property (nonatomic, copy) NSString *url; 12 @property (nonatomic, copy) NSString *url;
13 @property (nonatomic, copy) NSString *navTitle; 13 @property (nonatomic, copy) NSString *navTitle;
  14 +@property (nonatomic,assign) BOOL isFromLH;
14 15
15 @end 16 @end
CNLiveScioLive/Pages/Base/CNLiveWebViewController.m
@@ -8,9 +8,11 @@ @@ -8,9 +8,11 @@
8 8
9 #import "CNLiveWebViewController.h" 9 #import "CNLiveWebViewController.h"
10 #import <WebKit/WebKit.h> 10 #import <WebKit/WebKit.h>
  11 +#import <QMUIKit/QMUIKit.h>
11 12
12 @interface CNLiveWebViewController ()<WKScriptMessageHandler,WKNavigationDelegate,WKUIDelegate> 13 @interface CNLiveWebViewController ()<WKScriptMessageHandler,WKNavigationDelegate,WKUIDelegate>
13 @property(nonatomic,strong) WKWebView *webView; 14 @property(nonatomic,strong) WKWebView *webView;
  15 +@property(nonatomic,strong) QMUIMarqueeLabel *titleLable;
14 16
15 @end 17 @end
16 18
@@ -20,6 +22,11 @@ @@ -20,6 +22,11 @@
20 [self cleanCacheAndCookie]; 22 [self cleanCacheAndCookie];
21 23
22 } 24 }
  25 +-(void)viewDidDisappear:(BOOL)animated
  26 +{
  27 + [super viewDidDisappear:animated];
  28 + [[_webView configuration].userContentController removeScriptMessageHandlerForName:@"goback"];
  29 +}
23 - (void)viewDidLoad { 30 - (void)viewDidLoad {
24 [super viewDidLoad]; 31 [super viewDidLoad];
25 [self setUpNavigationBar]; 32 [self setUpNavigationBar];
@@ -44,10 +51,23 @@ @@ -44,10 +51,23 @@
44 [headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; 51 [headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
45 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton]; 52 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
46 53
  54 + if (_isFromLH) {
  55 + UIButton *shareButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
  56 + shareButton.layer.cornerRadius = 2.0;
  57 + shareButton.layer.masksToBounds = true;
  58 + [shareButton setImage:[UIImage imageNamed:@"cnlive_live_share"] forState:UIControlStateNormal];
  59 + [shareButton addTarget:self action:@selector(shareBtnTap) forControlEvents:UIControlEventTouchUpInside];
  60 + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:shareButton];
  61 + self.navigationItem.titleView = self.titleLable;
  62 + }
47 self.navigationItem.title = self.navTitle; 63 self.navigationItem.title = self.navTitle;
48 64
49 } 65 }
50 - 66 +#pragma mark - Action
  67 +- (void) shareBtnTap{
  68 + NSString *title = [NSString stringWithFormat:@"%@",self.titleLable.text];
  69 + [[TemplateShareManager manager] shareImage:@"" title:title text:@"" url:_url controller:self];
  70 +}
51 #pragma mark - WKNavigationDelegate 71 #pragma mark - WKNavigationDelegate
52 // 页面开始加载时调用 72 // 页面开始加载时调用
53 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{ 73 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
@@ -61,6 +81,12 @@ @@ -61,6 +81,12 @@
61 // 页面加载完成之后调用 81 // 页面加载完成之后调用
62 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{ 82 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
63 [MBProgressHUD hideHUDForView:self.view animated:YES]; 83 [MBProgressHUD hideHUDForView:self.view animated:YES];
  84 + if (!self.isFromLH) {
  85 + return;
  86 + }
  87 + [self.webView evaluateJavaScript:@"document.title" completionHandler:^(id object, NSError * error) {
  88 + self->_titleLable.text = object;
  89 + }];
64 90
65 } 91 }
66 // 页面加载失败时调用 92 // 页面加载失败时调用
@@ -119,10 +145,6 @@ @@ -119,10 +145,6 @@
119 } 145 }
120 } 146 }
121 147
122 -- (void)dealloc {  
123 - [[_webView configuration].userContentController removeScriptMessageHandlerForName:@"goback"];  
124 -  
125 -}  
126 - (void)didReceiveMemoryWarning { 148 - (void)didReceiveMemoryWarning {
127 [super didReceiveMemoryWarning]; 149 [super didReceiveMemoryWarning];
128 // Dispose of any resources that can be recreated. 150 // Dispose of any resources that can be recreated.
@@ -139,6 +161,15 @@ @@ -139,6 +161,15 @@
139 */ 161 */
140 162
141 #pragma mark - 懒加载 163 #pragma mark - 懒加载
  164 +- (QMUIMarqueeLabel *)titleLable
  165 +{
  166 + if (!_titleLable) {
  167 + _titleLable = [[QMUIMarqueeLabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 80, 44)];
  168 + _titleLable.textColor = [UIColor whiteColor];
  169 + _titleLable.textAlignment = NSTextAlignmentCenter;
  170 + }
  171 + return _titleLable;
  172 +}
142 - (WKWebView *)webView { 173 - (WKWebView *)webView {
143 if (!_webView) { 174 if (!_webView) {
144 175
CNLiveScioLive/Pages/Home/搜索/Controller/CNLiveSearchViewController.m
@@ -869,10 +869,11 @@ @@ -869,10 +869,11 @@
869 [self.navigationController pushViewController:vc animated:YES]; 869 [self.navigationController pushViewController:vc animated:YES];
870 870
871 } else if ([@"LK" isEqualToString:_dic[@"type"]]) { 871 } else if ([@"LK" isEqualToString:_dic[@"type"]]) {
872 - OldArticleDetailViewController *vc = [[OldArticleDetailViewController alloc] initWithDictionary:_dic];  
873 - vc.title = _dic[@"cmsColumnName"];  
874 - vc.hidesBottomBarWhenPushed = YES;  
875 - [self.navigationController pushViewController:vc animated:YES]; 872 + CNLiveWebViewController *webVC = [CNLiveWebViewController new];
  873 + webVC.url = [NSString stringWithFormat:@"%@",_dic[@"pageUrl"]];
  874 + webVC.isFromLH = YES;
  875 + webVC.hidesBottomBarWhenPushed = YES;
  876 + [self.navigationController pushViewController:webVC animated:YES];
876 877
877 } 878 }
878 879
CNLiveScioLive/Pages/Home/新闻详情/OldController/OldArticleDetailViewController.m
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 8
9 #import "OldArticleDetailViewController.h" 9 #import "OldArticleDetailViewController.h"
10 #import "OldVideoDetailViewController.h" 10 #import "OldVideoDetailViewController.h"
  11 +#import "CNLiveWebViewController.h"
11 12
12 #import "VideoTableViewCell.h" 13 #import "VideoTableViewCell.h"
13 #import "ArticleTableViewCell.h" 14 #import "ArticleTableViewCell.h"
@@ -44,6 +45,7 @@ @@ -44,6 +45,7 @@
44 } 45 }
45 return self; 46 return self;
46 } 47 }
  48 +
47 - (NSString *)setHTMLString:(NSString *)content author:(NSString *)author { 49 - (NSString *)setHTMLString:(NSString *)content author:(NSString *)author {
48 NSString* htmlcontent = [[NSString alloc] initWithFormat: 50 NSString* htmlcontent = [[NSString alloc] initWithFormat:
49 @"<!doctype html>\n" 51 @"<!doctype html>\n"
@@ -456,16 +458,22 @@ @@ -456,16 +458,22 @@
456 } else if (isHttp || isHttps || isMailto) { 458 } else if (isHttp || isHttps || isMailto) {
457 [[UIApplication sharedApplication] openURL:webView.URL]; 459 [[UIApplication sharedApplication] openURL:webView.URL];
458 decisionHandler(WKNavigationActionPolicyCancel); 460 decisionHandler(WKNavigationActionPolicyCancel);
459 - }  
460 - } else {  
461 - NSURL *requestURL = webView.URL;  
462 - if (([[requestURL scheme] isEqualToString: @"http"] || [[requestURL scheme] isEqualToString:@"https"] || [[requestURL scheme] isEqualToString: @"mailto" ]) && (navigationAction.navigationType == WKNavigationTypeLinkActivated)) {  
463 - [[UIApplication sharedApplication] openURL:webView.URL];  
464 - decisionHandler(WKNavigationActionPolicyCancel); 461 + return;
465 } 462 }
466 } 463 }
467 decisionHandler(WKNavigationActionPolicyAllow); 464 decisionHandler(WKNavigationActionPolicyAllow);
468 } 465 }
  466 +- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
  467 +{
  468 + NSString *webUrl = [NSString stringWithFormat:@"%@",webView.URL];
  469 + if (![webUrl isEqualToString:htmlUrl]) {
  470 + decisionHandler(WKNavigationResponsePolicyCancel);
  471 + CNLiveWebViewController *webVC = [CNLiveWebViewController new];
  472 + webVC.url = [NSString stringWithFormat:@"%@",webView.URL];
  473 + webVC.isFromLH = YES;
  474 + [self.navigationController pushViewController:webVC animated:YES];
  475 + }
  476 +}
469 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation { 477 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
470 [AlertViewTool showHUDView]; 478 [AlertViewTool showHUDView];
471 } 479 }
@@ -475,6 +483,7 @@ @@ -475,6 +483,7 @@
475 483
476 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation { 484 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation {
477 [AlertViewTool hideHUDView]; 485 [AlertViewTool hideHUDView];
  486 +
478 _imageArray = [_webView getImgs]; 487 _imageArray = [_webView getImgs];
479 NSMutableArray *array = [NSMutableArray array]; 488 NSMutableArray *array = [NSMutableArray array];
480 for (NSString *string in _imageArray) { 489 for (NSString *string in _imageArray) {
@@ -503,10 +512,10 @@ @@ -503,10 +512,10 @@
503 512
504 [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error){ 513 [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error){
505 CGFloat graphicLiveHeight = [result floatValue]; 514 CGFloat graphicLiveHeight = [result floatValue];
506 - heightArr[0] = [NSString stringWithFormat:@"%f", graphicLiveHeight];  
507 - _webView.height = graphicLiveHeight+30; 515 + self->heightArr[0] = [NSString stringWithFormat:@"%f", graphicLiveHeight];
  516 + self->_webView.height = graphicLiveHeight+30;
508 [self.tableView reloadData]; 517 [self.tableView reloadData];
509 - if (!hasLoad) { 518 + if (!self->hasLoad) {
510 [self loadProgramRelativeData]; 519 [self loadProgramRelativeData];
511 } 520 }
512 }]; 521 }];
@@ -28,6 +28,7 @@ target &#39;CNLiveScioLive&#39; do @@ -28,6 +28,7 @@ target &#39;CNLiveScioLive&#39; do
28 pod 'FMDB' 28 pod 'FMDB'
29 pod 'AvoidCrash', '~> 2.5.2' 29 pod 'AvoidCrash', '~> 2.5.2'
30 pod 'BaiduMobStatCodeless' 30 pod 'BaiduMobStatCodeless'
  31 + pod 'QMUIKit'
31 #基础请求组件库 32 #基础请求组件库
32 pod 'CNLiveRequestBastKit' 33 pod 'CNLiveRequestBastKit'
33 34