liurenjie
2021-05-15 4bbf311f46e31fba203e3cc21adc963a299fbb9b
Merge branch 'master' of ssh://193.112.35.168:29418/buwan-ios
2个文件已修改
81 ■■■■ 已修改文件
BuWanVideo2.0/Info.plist 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BuWanVideo2.0/WEBViewController.m 73 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
BuWanVideo2.0/Info.plist
@@ -23,6 +23,14 @@
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>iqiyi</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>iqiyi</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLIconFile</key>
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" ];
      // 关键代码, 必须实现这个方法, 否则第一次打开UA还是原始值, 待第二次打开webview才是正确的UA;
        [_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" ];
            // 关键代码, 必须实现这个方法, 否则第一次打开UA还是原始值, 待第二次打开webview才是正确的UA;
            [_webView setCustomUserAgent:systemUserAgent];
        }
    }];
    
    
    // 这行代码可以是侧滑返回webView的上一级,而不是跟控制器(*指针对侧滑有效)
@@ -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的host链接 ;
             如果是scheme跳转,就判断是否是 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];
        }