WebViewController.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //
  2. // WebViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 1/21/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "WebViewController.h"
  9. #import "RAUtils.h"
  10. #import "const.h"
  11. @interface WebViewController ()
  12. @end
  13. @implementation WebViewController
  14. - (void)viewWillAppear:(BOOL)animated
  15. {
  16. [super viewWillAppear:animated];
  17. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  18. }
  19. - (void)viewDidLoad
  20. {
  21. [super viewDidLoad];
  22. // self.edgesForExtendedLayout = UIRectEdgeNone;
  23. // Do any additional setup after loading the view.
  24. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  25. ref.tag = 200 ;
  26. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
  27. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  28. // ref.hidden = true;
  29. [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  30. [self.wkWebview.scrollView addSubview:ref];
  31. self.wkWebview.navigationDelegate = self;
  32. // self.wkWebview.dataDetectorTypes=UIDataDetectorTypeAll;
  33. // self.wkWebview datade
  34. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  35. style:UIBarButtonItemStylePlain
  36. target:self
  37. action:@selector( onBackClick:)];
  38. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  39. // closeButton.title = @"Close";
  40. // closeButton.tintColor = UIColorFromRGB(0x996633);
  41. self.navigationItem.leftBarButtonItem = closeButton;
  42. // self.url=@"http://192.168.1.3:8080/npd/test.pdf";
  43. // NSURL* url = [NSURL URLWithString:self.url];
  44. //
  45. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:2000];
  46. //
  47. //
  48. // [self.webView loadRequest:request];
  49. [self loadcontent];
  50. }
  51. - (void)onBackClick:(UIButton *)sender {
  52. if (self.backItemDismiss)
  53. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  54. [self.navigationController popViewControllerAnimated:FALSE];
  55. }
  56. -(void)ReloadData
  57. {
  58. // Count ++ ;
  59. // [mytabelview reloadData];
  60. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  61. [reF endRefreshing];
  62. [self loadcontent];
  63. }
  64. -(void) loadcontent
  65. {
  66. self.mum.hidden=false;
  67. NSURL *url =[NSURL URLWithString:self.url];
  68. DebugLog(self.url);
  69. NSURLRequest *request =[NSURLRequest requestWithURL:url];
  70. [self.wkWebview loadRequest:request];
  71. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  72. //
  73. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  74. //
  75. // //设置请求方式为get
  76. //
  77. // [request setHTTPMethod:@"GET"];
  78. //
  79. // //添加用户会话id
  80. //
  81. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  82. //
  83. // //连接发送请求
  84. //
  85. //
  86. // NSHTTPURLResponse* urlResponse = nil;
  87. //
  88. // NSError *error = [[NSError alloc] init];
  89. //
  90. // self.content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  91. //
  92. //
  93. //
  94. // dispatch_async(dispatch_get_main_queue(), ^{
  95. //
  96. // self.navigationItem.title = self.title;
  97. // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  98. // // self.content=nil;
  99. // if(self.content!=nil&&self.content.length>0)
  100. // {
  101. // [reF removeFromSuperview];
  102. //
  103. //
  104. //// // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  105. //// NSString *path = NSTemporaryDirectory();
  106. //// NSString *filePath = [path stringByAppendingPathComponent:self.filename];
  107. //// // NSError *error = [[NSError alloc] init];
  108. //// // BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  109. //// // NSAssert(bo,@"创建目录失败");
  110. //// [self.content writeToFile:filePath atomically:YES];
  111. ////
  112. ////
  113. //// self.btnshare.enabled =true;
  114. ////
  115. ////
  116. //// self.btnemail.enabled =true;
  117. //// self.btnsave.enabled =true;
  118. ////
  119. //// if(self.onLoadSuccess)
  120. //// self.onLoadSuccess(self.url);
  121. // // int a=0;
  122. // }
  123. // else
  124. // {
  125. // [RAUtils message_alert:nil title:@"Open URL Failed" controller:self];
  126. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  127. // }
  128. //
  129. // ;
  130. // // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  131. // //
  132. //
  133. //
  134. // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  135. //
  136. //
  137. //
  138. //
  139. // });
  140. // });
  141. }
  142. -(void)changeCell
  143. {
  144. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  145. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  146. if ([self respondsToSelector:@selector(ReloadData)])
  147. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  148. // DebugLog(@"refresh!!!!!!!!");
  149. }
  150. - (void)didReceiveMemoryWarning
  151. {
  152. [super didReceiveMemoryWarning];
  153. // Dispose of any resources that can be recreated.
  154. }
  155. #pragma mark - WKNavigationDelegate
  156. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
  157. {
  158. self.mum.hidden=true;
  159. }
  160. /*
  161. #pragma mark - Navigation
  162. // In a storyboard-based application, you will often want to do a little preparation before navigation
  163. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  164. // Get the new view controller using [segue destinationViewController].
  165. // Pass the selected object to the new view controller.
  166. }
  167. */
  168. @end