Commit 7563cc05867670fa096c0736a7532fd65cbcf1a3
1 parent
fec9ac1d
H5跳转分享问题解决
Showing
4 changed files
with
55 additions
and
14 deletions
CNLiveScioLive/Pages/Base/CNLiveWebViewController.h
CNLiveScioLive/Pages/Base/CNLiveWebViewController.m
| ... | ... | @@ -8,9 +8,11 @@ |
| 8 | 8 | |
| 9 | 9 | #import "CNLiveWebViewController.h" |
| 10 | 10 | #import <WebKit/WebKit.h> |
| 11 | +#import <QMUIKit/QMUIKit.h> | |
| 11 | 12 | |
| 12 | 13 | @interface CNLiveWebViewController ()<WKScriptMessageHandler,WKNavigationDelegate,WKUIDelegate> |
| 13 | 14 | @property(nonatomic,strong) WKWebView *webView; |
| 15 | +@property(nonatomic,strong) QMUIMarqueeLabel *titleLable; | |
| 14 | 16 | |
| 15 | 17 | @end |
| 16 | 18 | |
| ... | ... | @@ -20,6 +22,11 @@ |
| 20 | 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 | 30 | - (void)viewDidLoad { |
| 24 | 31 | [super viewDidLoad]; |
| 25 | 32 | [self setUpNavigationBar]; |
| ... | ... | @@ -44,10 +51,22 @@ |
| 44 | 51 | [headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; |
| 45 | 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 | 63 | self.navigationItem.title = self.navTitle; |
| 48 | 64 | |
| 49 | 65 | } |
| 50 | - | |
| 66 | +#pragma mark - Action | |
| 67 | +- (void) shareBtnTap{ | |
| 68 | + [[TemplateShareManager manager] shareImage:@"" title:@"" text:@"" url:_url controller:self]; | |
| 69 | +} | |
| 51 | 70 | #pragma mark - WKNavigationDelegate |
| 52 | 71 | // 页面开始加载时调用 |
| 53 | 72 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{ |
| ... | ... | @@ -61,6 +80,12 @@ |
| 61 | 80 | // 页面加载完成之后调用 |
| 62 | 81 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{ |
| 63 | 82 | [MBProgressHUD hideHUDForView:self.view animated:YES]; |
| 83 | + if (!self.isFromLH) { | |
| 84 | + return; | |
| 85 | + } | |
| 86 | + [self.webView evaluateJavaScript:@"document.title" completionHandler:^(id object, NSError * error) { | |
| 87 | + self->_titleLable.text = object; | |
| 88 | + }]; | |
| 64 | 89 | |
| 65 | 90 | } |
| 66 | 91 | // 页面加载失败时调用 |
| ... | ... | @@ -119,10 +144,6 @@ |
| 119 | 144 | } |
| 120 | 145 | } |
| 121 | 146 | |
| 122 | -- (void)dealloc { | |
| 123 | - [[_webView configuration].userContentController removeScriptMessageHandlerForName:@"goback"]; | |
| 124 | - | |
| 125 | -} | |
| 126 | 147 | - (void)didReceiveMemoryWarning { |
| 127 | 148 | [super didReceiveMemoryWarning]; |
| 128 | 149 | // Dispose of any resources that can be recreated. |
| ... | ... | @@ -139,6 +160,15 @@ |
| 139 | 160 | */ |
| 140 | 161 | |
| 141 | 162 | #pragma mark - 懒加载 |
| 163 | +- (QMUIMarqueeLabel *)titleLable | |
| 164 | +{ | |
| 165 | + if (!_titleLable) { | |
| 166 | + _titleLable = [[QMUIMarqueeLabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 80, 44)]; | |
| 167 | + _titleLable.textColor = [UIColor whiteColor]; | |
| 168 | + _titleLable.textAlignment = NSTextAlignmentCenter; | |
| 169 | + } | |
| 170 | + return _titleLable; | |
| 171 | +} | |
| 142 | 172 | - (WKWebView *)webView { |
| 143 | 173 | if (!_webView) { |
| 144 | 174 | ... | ... |
CNLiveScioLive/Pages/Home/新闻详情/OldController/OldArticleDetailViewController.m
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | #import "OldArticleDetailViewController.h" |
| 10 | 10 | #import "OldVideoDetailViewController.h" |
| 11 | +#import "CNLiveWebViewController.h" | |
| 11 | 12 | |
| 12 | 13 | #import "VideoTableViewCell.h" |
| 13 | 14 | #import "ArticleTableViewCell.h" |
| ... | ... | @@ -44,6 +45,7 @@ |
| 44 | 45 | } |
| 45 | 46 | return self; |
| 46 | 47 | } |
| 48 | + | |
| 47 | 49 | - (NSString *)setHTMLString:(NSString *)content author:(NSString *)author { |
| 48 | 50 | NSString* htmlcontent = [[NSString alloc] initWithFormat: |
| 49 | 51 | @"<!doctype html>\n" |
| ... | ... | @@ -456,16 +458,22 @@ |
| 456 | 458 | } else if (isHttp || isHttps || isMailto) { |
| 457 | 459 | [[UIApplication sharedApplication] openURL:webView.URL]; |
| 458 | 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 | 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 | 477 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation { |
| 470 | 478 | [AlertViewTool showHUDView]; |
| 471 | 479 | } |
| ... | ... | @@ -475,6 +483,7 @@ |
| 475 | 483 | |
| 476 | 484 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation { |
| 477 | 485 | [AlertViewTool hideHUDView]; |
| 486 | + | |
| 478 | 487 | _imageArray = [_webView getImgs]; |
| 479 | 488 | NSMutableArray *array = [NSMutableArray array]; |
| 480 | 489 | for (NSString *string in _imageArray) { |
| ... | ... | @@ -503,10 +512,10 @@ |
| 503 | 512 | |
| 504 | 513 | [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error){ |
| 505 | 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 | 517 | [self.tableView reloadData]; |
| 509 | - if (!hasLoad) { | |
| 518 | + if (!self->hasLoad) { | |
| 510 | 519 | [self loadProgramRelativeData]; |
| 511 | 520 | } |
| 512 | 521 | }]; | ... | ... |