| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //
- // WebViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 1/21/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "WebViewController.h"
- #import "RAUtils.h"
- #import "const.h"
- @interface WebViewController ()
- @end
- @implementation WebViewController
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [[self navigationController] setNavigationBarHidden:NO animated:NO];
-
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // self.edgesForExtendedLayout = UIRectEdgeNone;
- // Do any additional setup after loading the view.
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 200 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
- [self.webView.scrollView addSubview:ref];
-
-
- self.webView.dataDetectorTypes=UIDataDetectorTypeAll;
-
-
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onBackClick:)];
- //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
- // closeButton.title = @"Close";
- // closeButton.tintColor = UIColorFromRGB(0x996633);
- self.navigationItem.leftBarButtonItem = closeButton;
-
-
-
-
-
- // self.url=@"http://192.168.1.3:8080/npd/test.pdf";
- // NSURL* url = [NSURL URLWithString:self.url];
- //
- // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:2000];
- //
- //
- // [self.webView loadRequest:request];
-
-
- [self loadcontent];
- }
- - (void)onBackClick:(UIButton *)sender {
-
- if (self.backItemDismiss)
- [self.navigationController dismissViewControllerAnimated:YES completion:nil];
-
- [self.navigationController popViewControllerAnimated:FALSE];
- }
- -(void)ReloadData
- {
-
- // Count ++ ;
- // [mytabelview reloadData];
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
- [self loadcontent];
-
-
- }
- -(void) loadcontent
- {
- self.mum.hidden=false;
-
-
- NSURL *url =[NSURL URLWithString:self.url];
- NSLog(self.url);
- NSURLRequest *request =[NSURLRequest requestWithURL:url];
- [self.webView loadRequest:request];
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- //
- // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
- //
- // //设置请求方式为get
- //
- // [request setHTTPMethod:@"GET"];
- //
- // //添加用户会话id
- //
- // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
- //
- // //连接发送请求
- //
- //
- // NSHTTPURLResponse* urlResponse = nil;
- //
- // NSError *error = [[NSError alloc] init];
- //
- // self.content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
- //
- //
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // self.navigationItem.title = self.title;
- // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- // // self.content=nil;
- // if(self.content!=nil&&self.content.length>0)
- // {
- // [reF removeFromSuperview];
- //
- //
- //// // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- //// NSString *path = NSTemporaryDirectory();
- //// NSString *filePath = [path stringByAppendingPathComponent:self.filename];
- //// // NSError *error = [[NSError alloc] init];
- //// // BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
- //// // NSAssert(bo,@"创建目录失败");
- //// [self.content writeToFile:filePath atomically:YES];
- ////
- ////
- //// self.btnshare.enabled =true;
- ////
- ////
- //// self.btnemail.enabled =true;
- //// self.btnsave.enabled =true;
- ////
- //// if(self.onLoadSuccess)
- //// self.onLoadSuccess(self.url);
- // // int a=0;
- // }
- // else
- // {
- // [RAUtils message_alert:nil title:@"Open URL Failed" controller:self];
- // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
- // }
- //
- // ;
- // // NSLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
- // //
- //
- //
- // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
- //
- //
- //
- //
- // });
- // });
-
-
-
-
- }
- -(void)changeCell
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
- if ([self respondsToSelector:@selector(ReloadData)])
- [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
- // DebugLog(@"refresh!!!!!!!!");
-
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - web view delegate
- - (void)webViewDidFinishLoad:(UIWebView *)webView
- {
- self.mum.hidden=true;
-
-
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|