OldArticleDetailViewController.m 30.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
//
//  OldArticleDetailViewController.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/27.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "OldArticleDetailViewController.h"
#import "OldVideoDetailViewController.h"
#import "CNLiveWebViewController.h"

#import "VideoTableViewCell.h"
#import "ArticleTableViewCell.h"
#import "YWWebScrollView.h"
#import "Html5Utils.h"

@interface OldArticleDetailViewController ()<UIGestureRecognizerDelegate>{
    NSMutableArray *_imageArray;
    NSInteger typeFlag;
    NSString *htmlString;
    NSString *htmlUrl;
    BOOL isHaveVideo;
    NSInteger isFail;
}
@property (nonatomic, strong) UIButton *refresh;

@end
@implementation OldArticleDetailViewController
- (id)initWithDictionary:(NSDictionary*)dictionary{
    if (self = [super init]) {
        _dictionary = [NSDictionary dictionaryWithDictionary:dictionary];
        _imageArray = [[ NSMutableArray alloc] init];
        
        NSString *url = [NSString stringWithFormat:@"%@?from=ios",dictionary[@"pageUrl"]];
        htmlString = [NSString stringWithContentsOfURL:[NSURL URLWithString:url] encoding:NSUTF8StringEncoding error:nil];
        //替换掉html页面中的展示js
        NSString *replace=[htmlString stringByReplacingOccurrencesOfString:@"previewImage.start(obj);" withString:@""];
        htmlString=replace;
        htmlUrl=dictionary[@"pageUrl"];
        if ([htmlString containsString:@"<video"]) {
            isHaveVideo = YES;
            [[JGMusicManager shareMusicManager] playStop];
        }
    }
    return self;
}

- (NSString *)setHTMLString:(NSString *)content author:(NSString *)author {
    NSString* htmlcontent = [[NSString alloc] initWithFormat:
                            @"<!doctype html>\n"
                            "<html>\n"
                            "<head> \n"
                            "<meta charset=\"utf-8\"></meta>"
                            "<style type=\"text/css\"> \n"
                             ".justify \n"
                             "{ \n"
                                 "text-align: justify; \n"
                             "} \n"
                             ".justify > span \n"
                             "{ \n"
                                 "display: inline-block; \n"
                                 "padding-left: 100%; \n"
                             "}\n"
                            "</style> \n"
                            "</head> \n"
                            "<body>"
                            "<script type='text/javascript'>"
                            "window.onload = function(){\n"
                                "var $img = document.getElementsByTagName('img');\n"
                                "for(var p in  $img){\n"
                                   " $img[p].style.width = '100%%';\n"
                                    "$img[p].style.height = 'auto'\n"
                                "}\n"
                            "}"
                            "</script>\n"
                            "<div id=\"webview_content\" class=\"justify\"><p><font style=\"font-size:20px;\"><strong>%@</strong></font><p>%@</p><font color=\"#184085\">%@</font></p><div><font style=\"font-size:%@px;\">%@</font></div></div>"
                            "</body>"
                             "</html>",[_dictionary objectForKey:@"title"],[_dictionary objectForKey:@"createDate"],[NSString stringWithFormat:@"%@:%@",CustomStr(@"Source"), author?author:@"国新网"],fontArray[fontIndex],content];
//    NSString * htmlcontent = [NSString stringWithFormat:@"<div id=\"webview_content_wrapper\">%@<font style=\"font-size:%@px;\">%@</font></div>",htmlHeader,fontArray[fontIndex],content];
//    [htmlcontent stringByReplacingOccurrencesOfString:@"amp;" withString:@""];
    NSLog(@"htmlcontent = %@",htmlcontent);
    return htmlcontent;
}
- (void)loadData {
    //    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_dictionary[@"pageUrl"]]]];
    //    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<img" withString:@"<img style=\"width:100%; height:auto;\""];
//    [_webView loadHTMLString:[self setHTMLString:] baseURL:nil];
}
- (void)getDetailsData {
    // 详情数据
    NSDictionary *parameters = @{@"params":[NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"type\":\"program\",\"id\":\"%@\"}", _dictionary[@"cmsContentId"]]};
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:REQUESTURL(@"gxb/api/programDetail")
       parameters:parameters headers:nil
         progress:^(NSProgress * _Nonnull uploadProgress) {}
          success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
              // 请求成功,解析数据
              NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
//              NSLog(@"%@",dic);
              if ([dic[@"errorCode"] isEqualToString:@"0"]) {
                  [self->_webView loadHTMLString:[self setHTMLString:dic[@"content"] author:dic[@"author"]] baseURL:[NSURL URLWithString:self->_dictionary[@"pageUrl"]]];
                  self->isFail = 0;
                  self->_refresh.hidden = YES;

              } else {
                  self->isFail++;
                  [AlertViewTool showHUDViewText:dic[@"errorMessage"]];
                  if (self->isFail == 1) {
                      [self getDetailsData];
                  } else if (self->isFail > 1) {
                      self->_refresh.hidden = NO;
                  }
              }
                
          }
          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              // 请求失败
              [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
          }];
}

//加载相关文章
- (void)loadProgramRelativeData {
    if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
        [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
        return;
    }
    NSString *strUrl = REQUESTURL(@"gxb/api/programRelative");
    NSString *categoryId = [NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"cmsContentId\":\"%@\"}",_dictionary[@"cmsContentId"]];
    NSDictionary *parameters = @{@"params":categoryId};
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strUrl
       parameters:parameters headers:nil 
         progress:^(NSProgress * _Nonnull uploadProgress) {}
          success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        self.tableView.hidden = NO;
              // 请求成功,解析数据
              NSDictionary *_dic = [NSDictionary dictionaryWithDictionary:responseObject];
              NSLog(@"%@",_dic);
              if ([_dic[@"errorCode"] isEqualToString:@"0"]) {
                  self->hasLoad = YES;
                  NSArray *array = _dic[@"programs"];
                  if (0 != [array count]) {
                      self->_newsArray = [NSArray arrayWithArray:array];
                      [self.tableView reloadData];
                  }
              } else {
                  [AlertViewTool showHUDViewText:_dic[@"errorMessage"]];

              }
          }
          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              // 请求失败
              NSLog(@"%@", [error localizedDescription]);
              [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
          }];
}
- (void)loadMoreData {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
#pragma mark - UI
- (void)setUpNavigationBar{
    self.navigationController.navigationBar.barTintColor = Color_Blue;
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:18]};
    //左
    UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
    headerButton.layer.cornerRadius = 2.0;
    headerButton.layer.masksToBounds = true;
    [headerButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
    [headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
    self.navigationItem.title = _dictionary[@"cmsColumnName"];
    
}
- (void)viewDidDisappear:(BOOL)animated{
    [(AppDelegate *)[UIApplication sharedApplication].delegate initializeSDKConfiguration];
    
}
- (void)goBack{
    [(AppDelegate *)[UIApplication sharedApplication].delegate initializeSDKConfiguration];
    [self.navigationController popViewControllerAnimated:YES];

}
- (void)loadShareView {
    UIImageView *lineImage = [[UIImageView alloc] init];
    if (iPhoneX) {
        lineImage.frame = CGRectMake(0, MainScreenHeight - 44 - 34 - 88, MainScreenWidth, 1);
    } else {
        lineImage.frame = CGRectMake(0, MainScreenHeight - 64 - 44, MainScreenWidth, 1);
    }
    lineImage.backgroundColor = Color_Line;
    [self.view addSubview:lineImage];
    
    UIButton *fontSizeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [fontSizeButton setImage:[UIImage imageNamed:@"cnlive_fontsize"] forState:UIControlStateNormal];
    if (iPhoneX) {
        [fontSizeButton setFrame:CGRectMake((MainScreenWidth/2 - 33)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34 - 88, 33, 22)];
    } else {
        [fontSizeButton setFrame:CGRectMake((MainScreenWidth/2 - 33)/2, MainScreenHeight - 44  - 64 + (44 - 22)/2, 33, 22)];
    }
    [fontSizeButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:fontSizeButton];
    [fontSizeButton setTag:10000];
    
    UIButton *isFavoriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary];
    BOOL isIn = [[DBAction sharedDBAction] isInTable:[User_Defaults objectForKey:Language_Local] notice:notice];
    if (isIn) {
        [isFavoriteButton setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
    } else {
        [isFavoriteButton setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
    }
    if (iPhoneX) {
        [isFavoriteButton setFrame:CGRectMake((MainScreenWidth - 23)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34 - 88, 33, 22)];
    } else {
        [isFavoriteButton setFrame:CGRectMake((MainScreenWidth - 23)/2, MainScreenHeight - 44  - 64 + (44 - 22)/2, 33, 22)];
    }
    [isFavoriteButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:isFavoriteButton];
    [isFavoriteButton setTag:20000];
    
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareButton setImage:[UIImage imageNamed:@"cnlive_share"] forState:UIControlStateNormal];
    if (iPhoneX) {
        [shareButton setFrame:CGRectMake((MainScreenWidth*3/2 - 22)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34 - 88, 33, 22)];
    } else {
        [shareButton setFrame:CGRectMake((MainScreenWidth*3/2 - 22)/2, MainScreenHeight - 44 - 64 + (44 - 22)/2, 33, 22)];
    }
    [shareButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shareButton];
    [shareButton setTag:30000];
}
- (void)getWebViewHeight{
    [_webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error){
        CGFloat graphicLiveHeight = [heightArr[fontIndex] floatValue];
        if (graphicLiveHeight > 5.0) {
        } else {
            graphicLiveHeight = [result floatValue];
            heightArr[fontIndex] = [NSString stringWithFormat:@"%f", graphicLiveHeight];
        }
        _webView.height = graphicLiveHeight+30;
        UIView *view = self.tableView.tableHeaderView;
        view.frame = CGRectMake(0, 0, MainScreenWidth, _webView.height);
        self.tableView.tableHeaderView = view;
        [self.tableView reloadData];
    }];
}
- (void)shareButtonTaped:(id)sender {
    UIButton *btn = (UIButton *)sender;
    if (10000 == btn.tag) {
        if ([fontArray count] - 1 == fontIndex) {
            fontIndex = 0;
        } else {
            fontIndex++;
        }
        if (0 == fontIndex) {
            NSLog(@"0");
            [_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'" completionHandler:^(id _Nullable res, NSError * _Nullable error) {
                [self getWebViewHeight];
            }];
        } else if (1 == fontIndex) {
            NSLog(@"1");
            [_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '120%'" completionHandler:^(id _Nullable res, NSError * _Nullable error) {
                [self getWebViewHeight];
            }];
        } else if (2 == fontIndex) {
            NSLog(@"2");
            [_webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '140%'" completionHandler:^(id _Nullable res, NSError * _Nullable error) {
                [self getWebViewHeight];
            }];
        }
    } else if (20000 == btn.tag) {
        TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary];
        BOOL isIn = [[DBAction sharedDBAction] isInTable:[User_Defaults objectForKey:Language_Local] notice:notice];
        
        if (!isIn) {
            BOOL isInsert = [[DBAction sharedDBAction] insertTable:[User_Defaults objectForKey:Language_Local] notice:notice];
            if (isInsert) {
                [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"CollectSuccess")];
                [btn setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];

            }
        } else {
            BOOL isDelete = [[DBAction sharedDBAction] deleteTable:[User_Defaults objectForKey:Language_Local] notice:notice];
            if (isDelete) {
                [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"CancelCollect")];
                [btn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
            }
        }
    } else if (30000 == btn.tag) {
        NSString *img = [NSString stringWithFormat:@"%@",_dictionary[@"img"]];
        NSString *title = [NSString stringWithFormat:@"%@",_dictionary[@"title"]];
        NSString *text = [NSString stringWithFormat:@"%@",!_dictionary[@"desc"]||[_dictionary[@"desc"] isEqualToString:@""]?title:_dictionary[@"desc"]];
        NSString *url = [NSString stringWithFormat:@"%@",_dictionary[@"pageUrl"]];
        [[TemplateShareManager manager] shareImage:img title:title text:text url:url controller:self];
        return;
        
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    [self setUpNavigationBar];
    
    NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width, user-scalable=no'); document.getElementsByTagName('head')[0].appendChild(meta);";

    WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
    WKUserContentController *wkUController = [[WKUserContentController alloc] init];
    [wkUController addUserScript:wkUScript];

    WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
    wkWebConfig.userContentController = wkUController;
    
    
    _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 1) configuration:wkWebConfig];
    CGRect frame = _webView.frame;
    frame.size.height = 0;
    _webView.frame = frame;
    _webView.scrollView.backgroundColor = [UIColor whiteColor];
    _webView.scrollView.showsVerticalScrollIndicator = NO;
    _webView.backgroundColor = [UIColor whiteColor];
    _webView.navigationDelegate = self;
    _webView.UIDelegate = self;
    _webView.scrollView.scrollEnabled = NO;
    _webView.opaque = NO;
    if (iPhoneX) {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 88 - 44 - 34) style:UITableViewStyleGrouped];

    } else {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 64 - 44) style:UITableViewStyleGrouped];
    }
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    
    self.tableView.tableHeaderView = _webView;
    self.tableView.hidden = YES;

    
    self.errorLabe = [[UILabel alloc] initWithFrame:CGRectZero];
    self.errorLabe.backgroundColor = [UIColor clearColor];
    self.errorLabe.textColor = HEXCOLOR(0x333333);
    self.errorLabe.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:self.errorLabe];
    self.errorLabe.text = @"没有数据";
    self.errorLabe.hidden = YES;
    
    [self loadShareView];
    
    fontIndex = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
    heightArr = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0"]];
    fontArray = @[@"16",@"20",@"24"];
    hasLoad = NO;
//    [self loadData];
    [self getDetailsData];
    
    [self.view addSubview:self.refresh];
}
- (void)refreshDidClicked:(UIButton *)btn {
    [self getDetailsData];
}
- (UIButton *)refresh {
    if (!_refresh) {
        _refresh = [UIButton buttonWithType:UIButtonTypeCustom];
        _refresh.frame = CGRectMake(0, 0, 100, 40);
        _refresh.layer.masksToBounds = YES;
        _refresh.layer.cornerRadius = 5;
        _refresh.center = self.view.center;
        _refresh.backgroundColor = Color_Blue;
        [_refresh setTitle:@"重试" forState:UIControlStateNormal];
        [_refresh setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_refresh setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        _refresh.titleLabel.font = [UIFont systemFontOfSize:13];
        [_refresh addTarget:self action:@selector(refreshDidClicked:) forControlEvents:UIControlEventTouchUpInside];
        _refresh.adjustsImageWhenHighlighted = NO;
        _refresh.hidden = YES;
    }
    return _refresh;
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    NSError *error = nil;
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &error];
    [[AVAudioSession sharedInstance] setActive:YES error:nil];
    
    //计数统计
    
    if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/srbd/"]) {
        //深入报道
        [CNLiveStat event:@"srbdsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/zcjd/"]){
        //国新图说
        [CNLiveStat event:@"gxtssl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/gzdt/"]){
        //要闻
        [CNLiveStat event:@"ywsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/hyjj/"]){
        //焦点
        [CNLiveStat event:@"jdsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/lingdaoyaowen/"]){
        //领导要闻
        [CNLiveStat event:@"ldywsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/bw/"]){
        //部委
        [CNLiveStat event:@"bwsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/dfdt/"]){
        //地方外宣
        [CNLiveStat event:@"dfwxsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/scio/"]){
        //scio news
        [CNLiveStat event:@"newssl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/wqtw/"]){
        //往期图文
        [CNLiveStat event:@"wqtwsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/fbhgg/"]){
        //发布会公告
        [CNLiveStat event:@"fbhggsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/toutiao/"]){
        //头条
        [CNLiveStat event:@"ttsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/yidaiyilu/"]){
        //一带一路
        [CNLiveStat event:@"ydylsl"];
    }else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/zixun/"]){
        //资讯
        [CNLiveStat event:@"zxsl"];
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

#pragma mark - WebView加载H5页面区域
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    if (_imageArray.count) {
        NSURL *requestURL = webView.URL;
        BOOL isImg = [@"img" isEqualToString:[requestURL scheme]];
        BOOL isHttp = [[requestURL scheme] isEqualToString: @"http"];
        BOOL isHttps = [[requestURL scheme] isEqualToString: @"https"];
        BOOL isMailto = [[requestURL scheme] isEqualToString: @"mailto"];
        if (isImg) {
            NSString *requesturl = [[NSString stringWithFormat:@"%@",webView.URL] substringFromIndex:4];
            for (NSInteger indes = 0; indes < _imageArray.count; indes++) {
                NSString *url = [NSString stringWithFormat:@"%@",_imageArray[indes]];
                if ([url isEqualToString:requesturl]) {
                    [self pushPicController:requesturl withPoint:indes];//显示图集
                    break;
                }
            }
        } else if (isHttp || isHttps || isMailto) {
            [[UIApplication sharedApplication] openURL:webView.URL];
            decisionHandler(WKNavigationActionPolicyCancel);
            return;
        }
    }
    decisionHandler(WKNavigationActionPolicyAllow);
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
{
    NSString *webUrl = [NSString stringWithFormat:@"%@",webView.URL];
    if (![webUrl isEqualToString:htmlUrl]) {
        decisionHandler(WKNavigationResponsePolicyCancel);
        CNLiveWebViewController *webVC = [CNLiveWebViewController new];
        webVC.url = [NSString stringWithFormat:@"%@",webView.URL];
        webVC.isFromLH = YES;
        [self.navigationController pushViewController:webVC animated:YES];
    }
}
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
    [AlertViewTool showHUDView];
}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
    [AlertViewTool hideHUDView];
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation {
    [AlertViewTool hideHUDView];

    _imageArray = [_webView getImgs];
    NSMutableArray *array = [NSMutableArray array];
    for (NSString *string in _imageArray) {
        if ([string rangeOfString:@"cnliveimg.com/sites/"].location == NSNotFound && [string rangeOfString:@"html"].location == NSNotFound && [string rangeOfString:@"cnliveimg.com/main/"].location == NSNotFound) {
            [array addObject:string];
        }
    }
    _imageArray = array;
    [webView addClickEventOnImg];//有的图片没有点击事件
    
    //使页面中图片width=100%
    [self.webView evaluateJavaScript:
     @"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"var imgs = document.getElementById('article_content').getElementsByTagName('img')\";"
     "for(var i=0; i<imgs.length; i++){"
     "imgs[i].style.width = '100%';"
     "}"
     "document.getElementsByTagName('body')[0].appendChild(script);" completionHandler:nil];
    
    //通过css隐藏h5页面中头部和底部的logo
    NSString *cssString = @".container { display:none !important; }";
    NSString *javascriptString = @"var style = document.createElement('style'); style.innerHTML = '%@'; document.head.appendChild(style)";
    NSString *javascriptWithCSSString = [NSString stringWithFormat:javascriptString, cssString];
    [webView evaluateJavaScript:javascriptWithCSSString completionHandler:nil];
    
    [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result, NSError * _Nullable error){
        CGFloat graphicLiveHeight = [result floatValue];
        self->heightArr[0] = [NSString stringWithFormat:@"%f", graphicLiveHeight];
        self->_webView.height = graphicLiveHeight+30;
        [self.tableView reloadData];
        if (!self->hasLoad) {
            [self loadProgramRelativeData];
        }
    }];

}

-(void)pushPicController:(NSString *)url withPoint:(NSInteger)CurrentIndex {
    YWWebScrollView *scrollView = [[YWWebScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    scrollView.ScrollViewTag = CurrentIndex;
    scrollView.imageUrls = _imageArray;
    [[UIApplication sharedApplication].keyWindow addSubview:scrollView];
}

#pragma mark - TableView加载相关文章区域

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_newsArray count];
}
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
    return 86.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return _newsArray.count>0?30.0:0.00001;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 30)];
    view.hidden = _newsArray.count == 0;
    view.backgroundColor = [UIColor whiteColor];
    UIImageView *lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 1)];
    lineImage1.backgroundColor = Color_Line;
    [view addSubview:lineImage1];
    
    UILabel *relatedInformation = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, MainScreenWidth - 24, 30)];
    relatedInformation.backgroundColor = [UIColor clearColor];
    relatedInformation.textColor = HEXCOLOR(0x333333);
    relatedInformation.font = [UIFont systemFontOfSize:15];
    [view addSubview:relatedInformation];
    relatedInformation.text = CustomStr(@"RelevantInformation");
    return view;
}
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section {
    return _newsArray.count>0?6.0:0.00001;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 6)];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *_dic = _newsArray[indexPath.row];
    if ([@"program" isEqualToString:_dic[@"type"]]) {
        static NSString *identifier = @"videoCell";
        VideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[VideoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        [cell.backImage sd_setImageWithURL:[NSURL URLWithString:_dic[@"img"]] placeholderImage:[UIImage imageNamed:@"backDefault"]];
        cell.playImage.image = [UIImage imageNamed:@"playButton"];
        cell.titleLabel.text = _dic[@"title"];
        cell.timeLabel.text  = _dic[@"createDate"];
        return cell;
    } else if ([@"article" isEqualToString:_dic[@"type"]]) {
        static NSString *identifier = @"articleCell";
        ArticleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[ArticleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        [cell.backImage sd_setImageWithURL:[NSURL URLWithString:_dic[@"img"]] placeholderImage:[UIImage imageNamed:@"backDefault"]];
        cell.titleLabel.text = _dic[@"title"];
        cell.timeLabel.text  = _dic[@"createDate"];
        return cell;
    }
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"%@",_newsArray[indexPath.row]);
    NSDictionary *_dic = _newsArray[indexPath.row];
    [self pushViewTo:_dic];
}

#pragma mark -

- (void)pushViewTo:(NSDictionary *)_dic {
    if ([@"program" isEqualToString:_dic[@"type"]]) {
        OldVideoDetailViewController *vc = [[OldVideoDetailViewController alloc] initWithDictionary:_dic];
        vc.title = _dic[@"cmsColumnName"];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    } else if ([@"article" isEqualToString:_dic[@"type"]]) {
        OldArticleDetailViewController *vc = [[OldArticleDetailViewController alloc] initWithDictionary:_dic];
        vc.title = _dic[@"cmsColumnName"];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(void)viewDidLayoutSubviews{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
        [cell setSeparatorInset:UIEdgeInsetsZero];

    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
        [cell setLayoutMargins:UIEdgeInsetsZero];
}
- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

@end