我可以通过以下方式拦截UIWebView的初始加载请求:
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType.
我如何记录我正在加载的页面上的所有请求?
我可以通过以下方式拦截UIWebView的初始加载请求:
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType.
我如何记录我正在加载的页面上的所有请求?
NSURLProtocol
来截取应用程序发出的请求,包括所有来自Web视图的请求。
@interface PrintingCache : NSURLCache
{
}
@end
@implementation PrintingCache
- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request
{
NSLog(@"url %@", request.URL.absoluteString);
return [super cachedResponseForRequest:request];
}
@end
NSString *path = ...// the path to the cache file
NSUInteger discCapacity = 10*1024*1024;
NSUInteger memoryCapacity = 512*1024;
FilteredWebCache *cache = [[Printing alloc] initWithMemoryCapacity: memoryCapacity diskCapacity: discCapacity diskPath:path];
[NSURLCache setSharedURLCache:cache];
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"url %@", [[request URL] absoluteString]);
return YES;
}
这个可行:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"url %@", [[request URL] absoluteString]);
return YES;
}
请确保在[super viewDidLoad]
中放置webView.delegate = self;
,否则它将不会显示任何内容。
Exploring
的答案?因为那个答案是错误的。 - Popeye