From 4bbf311f46e31fba203e3cc21adc963a299fbb9b Mon Sep 17 00:00:00 2001 From: liurenjie <liurenjie@yuan9.cn> Date: 星期六, 15 五月 2021 10:43:16 +0800 Subject: [PATCH] Merge branch 'master' of ssh://193.112.35.168:29418/buwan-ios --- BuWanVideo2.0/WEBViewController.m | 73 +++++++++++++++++++++++++++--------- 1 files changed, 55 insertions(+), 18 deletions(-) diff --git a/BuWanVideo2.0/WEBViewController.m b/BuWanVideo2.0/WEBViewController.m index 168a86a..dda865c 100755 --- a/BuWanVideo2.0/WEBViewController.m +++ b/BuWanVideo2.0/WEBViewController.m @@ -40,17 +40,17 @@ [_webView setMultipleTouchEnabled:YES]; [_webView setAutoresizesSubviews:YES]; [_webView.scrollView setAlwaysBounceVertical:YES]; - // [_webView setCustomUserAgent:@"Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Mobile/15E148 Safari/604.1"]; - // 鑾峰彇褰撳墠UserAgent, 骞跺鍏惰繘琛屼慨鏀� - [_webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id userAgent, NSError * _Nullable error) { - if ([userAgent isKindOfClass:[NSString class]]) { - NSString *systemUserAgent =@""; - systemUserAgent = [NSString stringWithFormat:@"%@ %@", userAgent, @"Safari/604.1" ]; - // 鍏抽敭浠g爜, 蹇呴』瀹炵幇杩欎釜鏂规硶, 鍚﹀垯绗竴娆℃墦寮�UA杩樻槸鍘熷鍊�, 寰呯浜屾鎵撳紑webview鎵嶆槸姝g‘鐨刄A; - [_webView setCustomUserAgent:systemUserAgent]; - - } - }]; + // [_webView setCustomUserAgent:@"Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Mobile/15E148 Safari/604.1"]; + // 鑾峰彇褰撳墠UserAgent, 骞跺鍏惰繘琛屼慨鏀� + [_webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id userAgent, NSError * _Nullable error) { + if ([userAgent isKindOfClass:[NSString class]]) { + NSString *systemUserAgent =@""; + systemUserAgent = [NSString stringWithFormat:@"%@ %@", userAgent, @"Safari/604.1" ]; + // 鍏抽敭浠g爜, 蹇呴』瀹炵幇杩欎釜鏂规硶, 鍚﹀垯绗竴娆℃墦寮�UA杩樻槸鍘熷鍊�, 寰呯浜屾鎵撳紑webview鎵嶆槸姝g‘鐨刄A; + [_webView setCustomUserAgent:systemUserAgent]; + + } + }]; // 杩欒浠g爜鍙互鏄晶婊戣繑鍥瀢ebView鐨勪笂涓�绾э紝鑰屼笉鏄窡鎺у埗鍣紙*鎸囬拡瀵逛晶婊戞湁鏁堬級 @@ -139,6 +139,43 @@ } +-(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{ + WKNavigationActionPolicy policy = WKNavigationActionPolicyAllow; + @try { + NSString *url; + url = navigationAction.request.URL.absoluteString; + NSLog(@"閾炬帴锛�%@",url); + + if([url hasPrefix:@"iqiyi"]){ + if ([[UIApplication sharedApplication] + canOpenURL:[NSURL URLWithString:url]]){ + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; + } + }else{ + + + /* + 濡傛灉鏄煙鍚嶏紝鍒ゆ柇itunes鐨刪ost閾炬帴 锛� + 濡傛灉鏄痵cheme璺宠浆锛屽氨鍒ゆ柇鏄惁鏄� App Store 鐨� scheme + */ + + if([[navigationAction.request.URL host] isEqualToString:@"itunes.apple.com"] || [[navigationAction.request.URL scheme] isEqualToString:@"itms-apps"]) { + if ( [[UIApplication sharedApplication] openURL:navigationAction.request.URL]) { + policy = WKNavigationActionPolicyCancel; + NSLog(@"宸茶烦杞嚦App Store"); + } + } + + } + } @catch (NSException *exception) { + + } @finally { + + } + decisionHandler(policy); + +} + -(BOOL)shouldAutorotate{ return YES; @@ -153,7 +190,7 @@ } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"title"]) { + if ([keyPath isEqualToString:@"title"]) { if (object == _webView) { NSString *title = _webView.title; if(webtitle==nil){ @@ -169,12 +206,12 @@ } }else if ([keyPath isEqualToString:@"estimatedProgress"]) { if (object == _webView) { - // double progress = _webView.estimatedProgress; - // if(progress!=1){ - // [SVProgressHUD showProgress:progress status:@"鍔犺浇涓�"]; - // }else{ - // [SVProgressHUD dismiss]; - // } + // double progress = _webView.estimatedProgress; + // if(progress!=1){ + // [SVProgressHUD showProgress:progress status:@"鍔犺浇涓�"]; + // }else{ + // [SVProgressHUD dismiss]; + // } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } -- Gitblit v1.8.0