| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- //
- // WebViewController.m
- // Apex Mobile
- //
- // Created by Ray on 14-3-13.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "WebViewController.h"
- @interface WebViewController ()
- @end
- @implementation WebViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- -(void)ReloadData
- {
-
- // Count ++ ;
- // [mytabelview reloadData];
- [self loadcontent];
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- }
- -(void) loadcontent
- {
- self.mum.hidden=false;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30];
-
- //设置请求方式为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];
-
- self.filename = [urlResponse suggestedFilename];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- self.navigationItem.title = self.filename;
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- if(self.content!=nil)
- [reF removeFromSuperview];
- //
-
- [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"];
- [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
- DebugLog(@"refresh!!!!!!!!");
-
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- 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 loadcontent];
-
-
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)onSaveClick:(UIBarButtonItem *)sender {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [paths objectAtIndex:0];
- 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];
-
- sender.enabled = false;
- // self.navigationItem.rightBarButtonItem = nil;
- }
- #pragma mark - WKNavigationDelegate
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
- {
- NSLog(@"webview didFinishNavigation");
- // [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
- self.mum.hidden=YES;
- }
- /*
- #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
|