WebViewController.m 6.8 KB

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