Commit 7563cc05867670fa096c0736a7532fd65cbcf1a3
1 parent
fec9ac1d
H5跳转分享问题解决
Showing
4 changed files
with
55 additions
and
14 deletions
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,22 @@ | @@ -44,10 +51,22 @@ | ||
| 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 | + [[TemplateShareManager manager] shareImage:@"" title:@"" text:@"" url:_url controller:self]; | ||
| 69 | +} | ||
| 51 | #pragma mark - WKNavigationDelegate | 70 | #pragma mark - WKNavigationDelegate |
| 52 | // 页面开始加载时调用 | 71 | // 页面开始加载时调用 |
| 53 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{ | 72 | - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{ |
| @@ -61,6 +80,12 @@ | @@ -61,6 +80,12 @@ | ||
| 61 | // 页面加载完成之后调用 | 80 | // 页面加载完成之后调用 |
| 62 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{ | 81 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{ |
| 63 | [MBProgressHUD hideHUDForView:self.view animated:YES]; | 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,10 +144,6 @@ | ||
| 119 | } | 144 | } |
| 120 | } | 145 | } |
| 121 | 146 | ||
| 122 | -- (void)dealloc { | ||
| 123 | - [[_webView configuration].userContentController removeScriptMessageHandlerForName:@"goback"]; | ||
| 124 | - | ||
| 125 | -} | ||
| 126 | - (void)didReceiveMemoryWarning { | 147 | - (void)didReceiveMemoryWarning { |
| 127 | [super didReceiveMemoryWarning]; | 148 | [super didReceiveMemoryWarning]; |
| 128 | // Dispose of any resources that can be recreated. | 149 | // Dispose of any resources that can be recreated. |
| @@ -139,6 +160,15 @@ | @@ -139,6 +160,15 @@ | ||
| 139 | */ | 160 | */ |
| 140 | 161 | ||
| 141 | #pragma mark - 懒加载 | 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 | - (WKWebView *)webView { | 172 | - (WKWebView *)webView { |
| 143 | if (!_webView) { | 173 | if (!_webView) { |
| 144 | 174 |
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 | }]; |
Podfile
| @@ -28,6 +28,7 @@ target 'CNLiveScioLive' do | @@ -28,6 +28,7 @@ target 'CNLiveScioLive' 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 |