WebViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.webView.scrollView addSubview:ref];
  31. self.webView.dataDetectorTypes=UIDataDetectorTypeAll;
  32. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  33. style:UIBarButtonItemStylePlain
  34. target:self
  35. action:@selector( onBackClick:)];
  36. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  37. // closeButton.title = @"Close";
  38. // closeButton.tintColor = UIColorFromRGB(0x996633);
  39. self.navigationItem.leftBarButtonItem = closeButton;
  40. // self.url=@"http://192.168.1.3:8080/npd/test.pdf";
  41. // NSURL* url = [NSURL URLWithString:self.url];
  42. //
  43. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:2000];
  44. //
  45. //
  46. // [self.webView loadRequest:request];
  47. [self loadcontent];
  48. }
  49. - (void)onBackClick:(UIButton *)sender {
  50. [self.navigationController popViewControllerAnimated:FALSE];
  51. }
  52. -(void)ReloadData
  53. {
  54. // Count ++ ;
  55. // [mytabelview reloadData];
  56. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  57. [reF endRefreshing];
  58. [self loadcontent];
  59. }
  60. -(void) loadcontent
  61. {
  62. self.mum.hidden=false;
  63. NSURL *url =[NSURL URLWithString:self.url];
  64. NSLog(self.url);
  65. NSURLRequest *request =[NSURLRequest requestWithURL:url];
  66. [self.webView loadRequest:request];
  67. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  68. //
  69. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  70. //
  71. // //设置请求方式为get
  72. //
  73. // [request setHTTPMethod:@"GET"];
  74. //
  75. // //添加用户会话id
  76. //
  77. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  78. //
  79. // //连接发送请求
  80. //
  81. //
  82. // NSHTTPURLResponse* urlResponse = nil;
  83. //
  84. // NSError *error = [[NSError alloc] init];
  85. //
  86. // self.content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  87. //
  88. //
  89. //
  90. // dispatch_async(dispatch_get_main_queue(), ^{
  91. //
  92. // self.navigationItem.title = self.title;
  93. // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  94. // // self.content=nil;
  95. // if(self.content!=nil&&self.content.length>0)
  96. // {
  97. // [reF removeFromSuperview];
  98. //
  99. //
  100. //// // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  101. //// NSString *path = NSTemporaryDirectory();
  102. //// NSString *filePath = [path stringByAppendingPathComponent:self.filename];
  103. //// // NSError *error = [[NSError alloc] init];
  104. //// // BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  105. //// // NSAssert(bo,@"创建目录失败");
  106. //// [self.content writeToFile:filePath atomically:YES];
  107. ////
  108. ////
  109. //// self.btnshare.enabled =true;
  110. ////
  111. ////
  112. //// self.btnemail.enabled =true;
  113. //// self.btnsave.enabled =true;
  114. ////
  115. //// if(self.onLoadSuccess)
  116. //// self.onLoadSuccess(self.url);
  117. // // int a=0;
  118. // }
  119. // else
  120. // {
  121. // [RAUtils message_alert:nil title:@"Open URL Failed" controller:self];
  122. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  123. // }
  124. //
  125. // ;
  126. // // NSLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  127. // //
  128. //
  129. //
  130. // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  131. //
  132. //
  133. //
  134. //
  135. // });
  136. // });
  137. }
  138. -(void)changeCell
  139. {
  140. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  141. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  142. if ([self respondsToSelector:@selector(ReloadData)])
  143. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  144. // DebugLog(@"refresh!!!!!!!!");
  145. }
  146. - (void)didReceiveMemoryWarning
  147. {
  148. [super didReceiveMemoryWarning];
  149. // Dispose of any resources that can be recreated.
  150. }
  151. #pragma mark - web view delegate
  152. - (void)webViewDidFinishLoad:(UIWebView *)webView
  153. {
  154. self.mum.hidden=true;
  155. }
  156. /*
  157. #pragma mark - Navigation
  158. // In a storyboard-based application, you will often want to do a little preparation before navigation
  159. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  160. // Get the new view controller using [segue destinationViewController].
  161. // Pass the selected object to the new view controller.
  162. }
  163. */
  164. @end