-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIWebViewController.m
More file actions
110 lines (85 loc) · 2.94 KB
/
Copy pathUIWebViewController.m
File metadata and controls
110 lines (85 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// UIWebViewController.m
// WKWebView
//
// Created by Africa on 17/2/8.
// Copyright © 2017年 Africa. All rights reserved.
//
#import "UIWebViewController.h"
#import "UIViewController+NavgationBar.h"
@interface UIWebViewController ()<UIWebViewDelegate>
@property (nonatomic, weak) UIWebView *webView;
@property (nonatomic, strong) NSMutableArray *urlArray;
@end
@implementation UIWebViewController
-(NSMutableArray *)urlArray
{
if (!_urlArray) {
_urlArray = [NSMutableArray array];
}
return _urlArray;
}
-(void)dealloc
{
NSLog(@"页面销毁");
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setNavBarType:NavBarTypeDefault];
[self setNavLeftViewWithNavLeftType:NavLeftTypeBack andCustomView:nil];
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView.backgroundColor = [UIColor orangeColor];
webView.delegate = self;
self.webView = webView;
[self.view addSubview:webView];
NSURL *url = [NSURL URLWithString:@"http://www.soku.com/m/y/video?q=%E9%98%BF%E5%87%A1%E8%BE%BE%20%E7%89%87%E6%AE%B5#loaded"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[request setHTTPMethod:@"GET"];
[webView loadRequest:request];
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSDate *date = [NSDate date];
NSLog(@"date begin:%@",date);
NSString *urlStr = [request.URL absoluteString];
NSLog(@"urlStr:%@",urlStr);
if (![[self.urlArray.lastObject absoluteString] isEqualToString:urlStr]) {
[self.urlArray addObject:request.URL];
}
return YES;
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"%s",__func__);
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
NSDate *date = [NSDate date];
NSLog(@"date finish:%@",date);
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"网页加载失败");
}
- (void)leftBtnNavLeftTypeBackClick:(UIButton *)btn
{
if (self.urlArray.count > 1) {
[self setNavLeftSecondViewWithNavLeftType:NavLeftTypeClose andCustomView:nil];
[self.urlArray removeLastObject];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.urlArray.lastObject cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
[self.webView loadRequest:request];
}else
{
[self setNavLeftSecondViewWithNavLeftType:NavLeftTypeNone andCustomView:nil];
[self.navigationController popViewControllerAnimated:YES];
}
}
-(void)leftBtnNavLeftTypeCloseClick:(UIButton *)btn
{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end