Commit cc393de982b45d2286abe96de346e48b53b21fe6

Authored by 张旭
2 parents d30914be 6cab0421

Merge branch 'WKWebView' of bj.gitlab.cnlive.com:ios-team/ScioLive into WKWebView

CNLiveScioLive/Pages/Home/新闻详情/OldController/OldArticleDetailViewController.m
... ... @@ -41,17 +41,42 @@
41 41 }
42 42 return self;
43 43 }
44   -- (NSString *)setHTMLString {
  44 +- (NSString *)setHTMLString:(NSString *)content {
45 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 47 NSLog(@"htmlcontent = %@",htmlcontent);
48 48 return htmlcontent;
49 49 }
50 50 - (void)loadData {
51 51 // [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_dictionary[@"pageUrl"]]]];
52 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 81 - (void)loadProgramRelativeData {
57 82 if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
... ... @@ -92,18 +117,6 @@
92 117 - (void)loadMoreData {
93 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 120 #pragma mark - UI
108 121 - (void)setUpNavigationBar{
109 122 self.navigationController.navigationBar.barTintColor = Color_Blue;
... ... @@ -224,7 +237,7 @@
224 237 }
225 238 - (void)viewDidLoad {
226 239 [super viewDidLoad];
227   -// self.automaticallyAdjustsScrollViewInsets = NO;
  240 +
228 241 self.view.backgroundColor = [UIColor whiteColor];
229 242 [self setUpNavigationBar];
230 243  
... ... @@ -236,31 +249,8 @@
236 249  
237 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 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 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 256 WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
... ... @@ -276,13 +266,10 @@
276 266 _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - 64 - 44) configuration:wkWebConfig];
277 267 }
278 268 _webView.scrollView.backgroundColor = [UIColor whiteColor];
279   -// _webView.dataDetectorTypes = UIDataDetectorTypeNone;
  269 + _webView.scrollView.showsVerticalScrollIndicator = NO;
280 270 _webView.backgroundColor = [UIColor whiteColor];
281 271 _webView.navigationDelegate = self;
282 272 _webView.UIDelegate = self;
283   -// _webView.delegate = _progressProxy;
284   -// _webView.scalesPageToFit = YES;
285   - _webView.opaque = NO;
286 273 [self.scrollView addSubview:_webView];
287 274  
288 275 self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
... ... @@ -312,7 +299,8 @@
312 299 heightArr = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0"]];
313 300 fontArray = @[@"16",@"20",@"24"];
314 301 hasLoad = NO;
315   - [self loadData];
  302 +// [self loadData];
  303 + [self getDetailsData];
316 304 }
317 305  
318 306 - (void)viewWillAppear:(BOOL)animated {
... ...