Commit 6cab04210e35f667c46f58eae77460bc38a96472
1 parent
416514ba
no message
Showing
2 changed files
with
33 additions
and
45 deletions
CNLiveScioLive/Pages/Home/新闻详情/OldController/OldArticleDetailViewController.m
| @@ -41,17 +41,42 @@ | @@ -41,17 +41,42 @@ | ||
| 41 | } | 41 | } |
| 42 | return self; | 42 | return self; |
| 43 | } | 43 | } |
| 44 | -- (NSString *)setHTMLString { | 44 | +- (NSString *)setHTMLString:(NSString *)content { |
| 45 | NSString* htmlHeader = [[NSString alloc] initWithFormat:@"<p><font style=\"font-size:20px;\"><strong>%@</strong></font><p>%@</p><font color=\"#184085\">%@</font> </p>",[_dictionary objectForKey:@"title"],[_dictionary objectForKey:@"createDate"],@"来源 : 国新网"]; | 45 | NSString* htmlHeader = [[NSString alloc] initWithFormat:@"<p><font style=\"font-size:20px;\"><strong>%@</strong></font><p>%@</p><font color=\"#184085\">%@</font> </p>",[_dictionary objectForKey:@"title"],[_dictionary objectForKey:@"createDate"],@"来源 : 国新网"]; |
| 46 | - NSString * htmlcontent = [NSString stringWithFormat:@"<div id=\"webview_content_wrapper\">%@<font style=\"font-size:%@px;\">%@</font></div>",htmlHeader,fontArray[fontIndex],[_dicArticle objectForKey:@"content"]]; | 46 | + NSString * htmlcontent = [NSString stringWithFormat:@"<div id=\"webview_content_wrapper\">%@<font style=\"font-size:%@px;\">%@</font></div>",htmlHeader,fontArray[fontIndex],content]; |
| 47 | NSLog(@"htmlcontent = %@",htmlcontent); | 47 | NSLog(@"htmlcontent = %@",htmlcontent); |
| 48 | return htmlcontent; | 48 | return htmlcontent; |
| 49 | } | 49 | } |
| 50 | - (void)loadData { | 50 | - (void)loadData { |
| 51 | // [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_dictionary[@"pageUrl"]]]]; | 51 | // [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_dictionary[@"pageUrl"]]]]; |
| 52 | // htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<img" withString:@"<img style=\"width:100%; height:auto;\""]; | 52 | // htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<img" withString:@"<img style=\"width:100%; height:auto;\""]; |
| 53 | - [_webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:htmlUrl]]; | 53 | +// [_webView loadHTMLString:[self setHTMLString:] baseURL:nil]; |
| 54 | } | 54 | } |
| 55 | +- (void)getDetailsData { | ||
| 56 | + // 详情数据 | ||
| 57 | + NSDictionary *parameters = @{@"params":[NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"type\":\"article\",\"id\":\"%@\"}", _dictionary[@"cmsContentId"]]}; | ||
| 58 | + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; | ||
| 59 | + [manager POST:@"http://app.phonemovie.cnlive.com/gxb/api/programDetail" | ||
| 60 | + parameters:parameters headers:nil | ||
| 61 | + progress:^(NSProgress * _Nonnull uploadProgress) {} | ||
| 62 | + success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { | ||
| 63 | + // 请求成功,解析数据 | ||
| 64 | + NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject]; | ||
| 65 | +// NSLog(@"%@",dic); | ||
| 66 | + if ([dic[@"errorCode"] isEqualToString:@"0"]) { | ||
| 67 | + [_webView loadHTMLString:[self setHTMLString:dic[@"content"]] baseURL:nil]; | ||
| 68 | + | ||
| 69 | + } else { | ||
| 70 | + [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; | ||
| 71 | + | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { | ||
| 75 | + // 请求失败 | ||
| 76 | + [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")]; | ||
| 77 | + }]; | ||
| 78 | +} | ||
| 79 | + | ||
| 55 | //加载相关文章 | 80 | //加载相关文章 |
| 56 | - (void)loadProgramRelativeData { | 81 | - (void)loadProgramRelativeData { |
| 57 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { | 82 | if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) { |
| @@ -92,18 +117,6 @@ | @@ -92,18 +117,6 @@ | ||
| 92 | - (void)loadMoreData { | 117 | - (void)loadMoreData { |
| 93 | [self.navigationController popToRootViewControllerAnimated:YES]; | 118 | [self.navigationController popToRootViewControllerAnimated:YES]; |
| 94 | } | 119 | } |
| 95 | -//- (void)setNaviation{ | ||
| 96 | -// self.navigationController.navigationBar.translucent = NO; | ||
| 97 | -// [self.navigationController.navigationBar setBarTintColor:HEXCOLOR(0x195ac9)]; | ||
| 98 | -// [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:20],NSFontAttributeName,[UIColor whiteColor],NSForegroundColorAttributeName,nil]]; | ||
| 99 | -// UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
| 100 | -// [leftButton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside]; | ||
| 101 | -// [leftButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal]; | ||
| 102 | -// [leftButton setFrame:CGRectMake(0, 0, 44, 44)]; | ||
| 103 | -// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton]; | ||
| 104 | -// self.navigationItem.hidesBackButton = YES; | ||
| 105 | -// self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; | ||
| 106 | -//} | ||
| 107 | #pragma mark - UI | 120 | #pragma mark - UI |
| 108 | - (void)setUpNavigationBar{ | 121 | - (void)setUpNavigationBar{ |
| 109 | self.navigationController.navigationBar.barTintColor = Color_Blue; | 122 | self.navigationController.navigationBar.barTintColor = Color_Blue; |
| @@ -224,7 +237,7 @@ | @@ -224,7 +237,7 @@ | ||
| 224 | } | 237 | } |
| 225 | - (void)viewDidLoad { | 238 | - (void)viewDidLoad { |
| 226 | [super viewDidLoad]; | 239 | [super viewDidLoad]; |
| 227 | -// self.automaticallyAdjustsScrollViewInsets = NO; | 240 | + |
| 228 | self.view.backgroundColor = [UIColor whiteColor]; | 241 | self.view.backgroundColor = [UIColor whiteColor]; |
| 229 | [self setUpNavigationBar]; | 242 | [self setUpNavigationBar]; |
| 230 | 243 | ||
| @@ -236,31 +249,8 @@ | @@ -236,31 +249,8 @@ | ||
| 236 | 249 | ||
| 237 | self.scrollView.backgroundColor = [UIColor whiteColor]; | 250 | self.scrollView.backgroundColor = [UIColor whiteColor]; |
| 238 | 251 | ||
| 239 | - // MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)]; | ||
| 240 | - // MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)]; | ||
| 241 | - // NSMutableArray *refreshingImages = [NSMutableArray array]; | ||
| 242 | - // for (NSUInteger i = 1; i <= 4; i++) { | ||
| 243 | - // UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"refresh0%zd", i]]; | ||
| 244 | - // [refreshingImages addObject:image]; | ||
| 245 | - // } | ||
| 246 | - // [footer setImages:refreshingImages forState:MJRefreshStateRefreshing]; | ||
| 247 | - // [footer setTitle:@"上拉关闭当前页" forState:MJRefreshStateIdle]; | ||
| 248 | - // [footer setTitle:@"放开关闭当前页" forState:MJRefreshStatePulling]; | ||
| 249 | - // [footer setTitle:@"正在关闭当前页" forState:MJRefreshStateRefreshing]; | ||
| 250 | - // [self.scrollView setHeader:header]; | ||
| 251 | - // [self.scrollView setFooter:footer]; | ||
| 252 | [self.view addSubview:self.scrollView]; | 252 | [self.view addSubview:self.scrollView]; |
| 253 | 253 | ||
| 254 | -// _progressProxy = [[NJKWebViewProgress alloc] init]; | ||
| 255 | -// _progressProxy.webViewProxyDelegate = self; | ||
| 256 | -// _progressProxy.progressDelegate = self; | ||
| 257 | - | ||
| 258 | -// CGFloat progressBarHeight = 2.f; | ||
| 259 | -// CGRect navigationBarBounds = self.navigationController.navigationBar.bounds; | ||
| 260 | -// CGRect barFrame = CGRectMake(0, navigationBarBounds.size.height, navigationBarBounds.size.width, progressBarHeight); | ||
| 261 | -// _progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame]; | ||
| 262 | -// _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin; | ||
| 263 | - | ||
| 264 | NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"; | 254 | NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"; |
| 265 | 255 | ||
| 266 | WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]; | 256 | WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES]; |
| @@ -276,13 +266,10 @@ | @@ -276,13 +266,10 @@ | ||
| 276 | _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 64 - 44) configuration:wkWebConfig]; | 266 | _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 64 - 44) configuration:wkWebConfig]; |
| 277 | } | 267 | } |
| 278 | _webView.scrollView.backgroundColor = [UIColor whiteColor]; | 268 | _webView.scrollView.backgroundColor = [UIColor whiteColor]; |
| 279 | -// _webView.dataDetectorTypes = UIDataDetectorTypeNone; | 269 | + _webView.scrollView.showsVerticalScrollIndicator = NO; |
| 280 | _webView.backgroundColor = [UIColor whiteColor]; | 270 | _webView.backgroundColor = [UIColor whiteColor]; |
| 281 | _webView.navigationDelegate = self; | 271 | _webView.navigationDelegate = self; |
| 282 | _webView.UIDelegate = self; | 272 | _webView.UIDelegate = self; |
| 283 | -// _webView.delegate = _progressProxy; | ||
| 284 | -// _webView.scalesPageToFit = YES; | ||
| 285 | - _webView.opaque = NO; | ||
| 286 | [self.scrollView addSubview:_webView]; | 273 | [self.scrollView addSubview:_webView]; |
| 287 | 274 | ||
| 288 | self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; | 275 | self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; |
| @@ -312,7 +299,8 @@ | @@ -312,7 +299,8 @@ | ||
| 312 | heightArr = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0"]]; | 299 | heightArr = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0"]]; |
| 313 | fontArray = @[@"16",@"20",@"24"]; | 300 | fontArray = @[@"16",@"20",@"24"]; |
| 314 | hasLoad = NO; | 301 | hasLoad = NO; |
| 315 | - [self loadData]; | 302 | +// [self loadData]; |
| 303 | + [self getDetailsData]; | ||
| 316 | } | 304 | } |
| 317 | 305 | ||
| 318 | - (void)viewWillAppear:(BOOL)animated { | 306 | - (void)viewWillAppear:(BOOL)animated { |
Podfile
| @@ -26,7 +26,7 @@ target 'CNLiveScioLive' do | @@ -26,7 +26,7 @@ target 'CNLiveScioLive' do | ||
| 26 | pod 'MBProgressHUD', '~> 1.1.0' | 26 | pod 'MBProgressHUD', '~> 1.1.0' |
| 27 | pod 'TYAttributedLabel', '~> 2.6.2' | 27 | pod 'TYAttributedLabel', '~> 2.6.2' |
| 28 | pod 'FMDB' | 28 | pod 'FMDB' |
| 29 | - pod 'NJKWebViewProgress' | 29 | +# pod 'NJKWebViewProgress' |
| 30 | pod 'AvoidCrash', '~> 2.5.2' | 30 | pod 'AvoidCrash', '~> 2.5.2' |
| 31 | pod 'BaiduMobStatCodeless' | 31 | pod 'BaiduMobStatCodeless' |
| 32 | #基础请求组件库 | 32 | #基础请求组件库 |