Commit 8673609002236409a5ffd6357334fe565f388940

Authored by yanglingyu
1 parent e030152b

直播图文详情接口更改

CNLiveScioLive/AppDelegate.m
... ... @@ -101,10 +101,10 @@
101 101 NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json];
102 102 NSURL *url = [NSURL URLWithString:dic[@"data"][@"image"]];
103 103 NSString * mode = dic[@"grayMode"];
104   - if (mode.intValue == 1) {
  104 + if (mode&&mode.intValue == 1) {
105 105 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:ISGRAYMODE];
106 106 }else{
107   - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:ISGRAYMODE];
  107 + [[NSUserDefaults standardUserDefaults] setBool:NO forKey:ISGRAYMODE];
108 108 }
109 109 if (dic[@"homeTitleColor"]&&![dic[@"homeTitleColor"] isEqualToString:@""]) {
110 110 [[NSUserDefaults standardUserDefaults] setValue:dic[@"homeTitleColor"] forKey:HOMETITLECOLOR];
... ...
CNLiveScioLive/Pages/Live/Controller/GraphicLiveViewController.m
... ... @@ -55,14 +55,42 @@
55 55  
56 56 - (void)loadData {
57 57 if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
  58 + [self setUpUIWithTag:1000 Height:0];
  59 + return;
  60 + }
  61 +
  62 + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  63 + manager.responseSerializer = [AFHTTPResponseSerializer serializer];
  64 + [manager POST:@"http://s.scio.gov.cn/ocms/.content/function_provider/arswitch1.json" parameters:nil headers:nil progress:NULL success:^(NSURLSessionDataTask *task, id responseObject) {
  65 + NSLog(@"%@",responseObject);
  66 + NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
  67 + NSString *errorCode = dic[@"errorCode"];
  68 +
  69 + if ([errorCode isEqualToString:@"1"]) {
  70 + [self requestJsonData:dic[@"docId"]];
  71 + }
  72 +
  73 +
  74 + } failure:^(NSURLSessionDataTask *task, NSError *error) {
  75 + NSLog(@"%@",error);
  76 + [self setUpUIWithTag:1000 Height:0];
  77 +
  78 + }];
  79 +
  80 +
  81 +}
  82 +-(void)requestJsonData:(NSString *)docId
  83 +{
  84 + if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
58 85 [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
59 86 return;
60 87 }
61 88 [AlertViewTool showHUDView];
62 89 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
63 90 manager.responseSerializer = [AFHTTPResponseSerializer serializer];
64   - [manager POST:tuwenzhibo parameters:nil headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  91 + [manager POST:tuwen(docId.intValue) parameters:nil headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
65 92 [AlertViewTool hideHUDView];
  93 + [self setUpUIWithTag:1000 Height:40.0];
66 94 // 请求成功,解析数据
67 95 NSString * jsonString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
68 96 NSArray *arr = [jsonString objectFromJSONString];
... ... @@ -72,7 +100,7 @@
72 100 } else {
73 101 [self->_webView loadHTMLString:@"<html><body> </body></html>" baseURL:nil];
74 102 }
75   -
  103 +
76 104  
77 105 } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
78 106 // 请求失败
... ... @@ -82,7 +110,6 @@
82 110  
83 111 }];
84 112 }
85   -
86 113 - (void)viewWillAppear:(BOOL)animated {
87 114 [super viewWillAppear:animated];
88 115 [[JGMusicManager shareMusicManager] playStop];
... ... @@ -96,7 +123,6 @@
96 123 - (void)viewWillDisappear:(BOOL)animated {
97 124 [super viewWillDisappear:animated];
98 125 [self.liveController stopShow];
99   -// self.liveController = nil;
100 126 [self.navigationController setNavigationBarHidden:NO];
101 127 }
102 128  
... ... @@ -117,15 +143,6 @@
117 143 backgroundView.bounces = NO;
118 144 [self.view addSubview:backgroundView];
119 145  
120   - relatedWebView = [[WKWebView alloc] initWithFrame:CGRectZero];
121   - relatedWebView.scrollView.backgroundColor = [UIColor whiteColor];
122   -// relatedWebView.dataDetectorTypes = UIDataDetectorTypeNone;
123   - relatedWebView.backgroundColor = [UIColor whiteColor];
124   - relatedWebView.scrollView.bounces = NO;
125   - relatedWebView.navigationDelegate = self;
126   - relatedWebView.opaque = NO;
127   - relatedWebView.tag = 1000;
128   - [backgroundView addSubview:relatedWebView];
129 146  
130 147 // NSString* htmlHeader = [[NSString alloc] initWithFormat:@"<html><font style=\"font-size:20px;\"><strong>%@</strong></font><br><p>%@</p><p>来源 : 国新网</p><body>",[_dictionary objectForKey:@"title"],[_dictionary objectForKey:@"liveStartDateTime"]];
131 148 // NSString* htmlFooter = [[NSString alloc] initWithFormat:@"<div class=\"logo\" style=\"text-indent:2em\">%@</div></body></html>",[_dictionary objectForKey:@"Description"]];
... ... @@ -156,16 +173,6 @@
156 173 NSString* strHtml = [[NSString alloc] initWithFormat:@"%@%@",htmlHeader,htmlFooter];
157 174 [relatedWebView loadHTMLString:strHtml baseURL:nil];
158 175  
159   - _webView = [[WKWebView alloc] initWithFrame:CGRectZero];
160   - _webView.scrollView.backgroundColor = [UIColor whiteColor];
161   -// _webView.dataDetectorTypes = UIDataDetectorTypeNone;
162   - _webView.backgroundColor = [UIColor whiteColor];
163   - _webView.navigationDelegate = self;
164   - _webView.opaque = NO;
165   - _webView.tag = 2000;
166   - _webView.hidden = YES;
167   - [backgroundView addSubview:_webView];
168   -
169 176 if (!isPlay) {
170 177 [self loadMovieView];
171 178 } else {
... ... @@ -329,26 +336,47 @@
329 336 [relatedWebView setFrame:CGRectMake(0, 0, MainScreenWidth, descriptionHeight)];
330 337 }];
331 338 }
332   -
333   - if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
334   - [self setUpUIWithTag:webView.tag Height:0];
335   - return;
336   - }
337   -
338   - AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
339   - manager.responseSerializer = [AFHTTPResponseSerializer serializer];
340   - [manager POST:@"http://s.scio.gov.cn/ocms/.content/function_provider/arswitch.json" parameters:nil headers:nil progress:NULL success:^(NSURLSessionDataTask *task, id responseObject) {
341   - NSLog(@"%@",responseObject);
342   - NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
343   - NSString *errorCode = dic[@"errorCode"];
344   - [self setUpUIWithTag:webView.tag Height:[errorCode isEqualToString:@"1"]?40.0:0.0];
345   -
346   - } failure:^(NSURLSessionDataTask *task, NSError *error) {
347   - NSLog(@"%@",error);
348   - [self setUpUIWithTag:webView.tag Height:0];
  339 + if (webView.tag==2000) {
  340 + CGFloat width = MainScreenWidth - 20;
  341 + NSString *string = [NSString stringWithFormat:
  342 + @"var script = document.createElement('script');"
  343 + "script.type = 'text/javascript';"
  344 + "script.text = \"function ResizeImages() { "
  345 + "var myimg,oldwidth;"
  346 + "var maxwidth=%f;" //缩放系数
  347 + "for(i=0;i <document.images.length;i++){"
  348 + "myimg = document.images[i];"
  349 + "if(myimg.width > maxwidth){"
  350 + "oldwidth = myimg.width;"
  351 + "myimg.width = maxwidth;"
  352 + "myimg.height = myimg.height * (maxwidth/oldwidth);"
  353 + "}"
  354 + "}"
  355 + "}\";"
  356 + "document.getElementsByTagName('head')[0].appendChild(script);",width];
349 357  
350   - }];
351   -
  358 + [webView evaluateJavaScript:string completionHandler:nil];
  359 + [webView evaluateJavaScript:@"ResizeImages();" completionHandler:nil];
  360 +
  361 + CGRect frame = webView.frame;
  362 + frame.size.width = MainScreenWidth;
  363 + frame.size.height = 1;
  364 + webView.frame = frame;
  365 + [webView evaluateJavaScript:@"document.body.scrollHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){
  366 + self->graphicLiveHeight = [result floatValue];
  367 + if (0 == [self->heightArr[self->fontIndex] floatValue]) {
  368 + [self->heightArr replaceObjectAtIndex:self->fontIndex withObject:[NSString stringWithFormat:@"%f",self->graphicLiveHeight]];
  369 + }
  370 +
  371 + if (self->isShow) {
  372 + NSLog(@"fontIndex = %d",self->fontIndex);
  373 + [self->backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + self->descriptionHeight + [self->heightArr[self->fontIndex] floatValue] + 221)];
  374 + [webView setFrame:CGRectMake(0, 40 + self->descriptionHeight, MainScreenWidth, [self->heightArr[self->fontIndex] floatValue])];
  375 + [self showRelatedInformation:40 + self->descriptionHeight + [self->heightArr[self->fontIndex] floatValue]];
  376 + }
  377 + }];
  378 + }
  379 +
352 380 }
353 381 - (void)setUpUIWithTag:(NSInteger)tag Height:(NSInteger)height{
354 382  
... ... @@ -418,58 +446,6 @@
418 446  
419 447 [self showRelatedInformation:height + descriptionHeight];
420 448  
421   - } else if (2000 == tag) {
422   - CGFloat width = MainScreenWidth - 20;
423   - NSString *string = [NSString stringWithFormat:
424   - @"var script = document.createElement('script');"
425   - "script.type = 'text/javascript';"
426   - "script.text = \"function ResizeImages() { "
427   - "var myimg,oldwidth;"
428   - "var maxwidth=%f;" //缩放系数
429   - "for(i=0;i <document.images.length;i++){"
430   - "myimg = document.images[i];"
431   - "if(myimg.width > maxwidth){"
432   - "oldwidth = myimg.width;"
433   - "myimg.width = maxwidth;"
434   - "myimg.height = myimg.height * (maxwidth/oldwidth);"
435   - "}"
436   - "}"
437   - "}\";"
438   - "document.getElementsByTagName('head')[0].appendChild(script);",width];
439   -
440   - [_webView evaluateJavaScript:string completionHandler:nil];
441   - [_webView evaluateJavaScript:@"ResizeImages();" completionHandler:nil];
442   -
443   - CGRect frame = _webView.frame;
444   - frame.size.width = MainScreenWidth;
445   - frame.size.height = 1;
446   - _webView.frame = frame;
447   - [_webView evaluateJavaScript:@"document.body.scrollHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){
448   - graphicLiveHeight = [result floatValue];
449   - if (0 == [heightArr[fontIndex] floatValue]) {
450   - [heightArr replaceObjectAtIndex:fontIndex withObject:[NSString stringWithFormat:@"%f",graphicLiveHeight]];
451   - }
452   -
453   - if (isShow) {
454   - NSLog(@"fontIndex = %d",fontIndex);
455   - [backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + descriptionHeight + [heightArr[fontIndex] floatValue] + 221)];
456   - [_webView setFrame:CGRectMake(0, 40 + descriptionHeight, MainScreenWidth, [heightArr[fontIndex] floatValue])];
457   - [self showRelatedInformation:40 + descriptionHeight + [heightArr[fontIndex] floatValue]];
458   - }
459   - }];
460   -
461   - NSLog(@"%@",NSStringFromCGRect(_webView.frame));
462   - NSLog(@"%@",NSStringFromCGSize(_webView.scrollView.contentSize));
463   -// if (0 == [heightArr[fontIndex] floatValue]) {
464   -// [heightArr replaceObjectAtIndex:fontIndex withObject:[NSString stringWithFormat:@"%f",graphicLiveHeight]];
465   -// }
466   -//
467   -// if (isShow) {
468   -// NSLog(@"fontIndex = %d",fontIndex);
469   -// [backgroundView setContentSize:CGSizeMake(MainScreenWidth, 40 + descriptionHeight + [heightArr[fontIndex] floatValue] + 221)];
470   -// [_webView setFrame:CGRectMake(0, 40 + descriptionHeight, MainScreenWidth, [heightArr[fontIndex] floatValue])];
471   -// [self showRelatedInformation:40 + descriptionHeight + [heightArr[fontIndex] floatValue]];
472   -// }
473 449 }
474 450 }
475 451  
... ...