1.內(nèi)存消耗
2.獲取URL立由、scheme榛鼎、resourceSpecifier
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
if ([[IPLLoginManager sharedInstance] isScheme:url.scheme])
{
[IPLLoginManager sharedInstance].resourceSpecifier =
url.resourceSpecifier;
[[IPLLoginManager sharedInstance] getLoadString];
[[IPLLoginManager sharedInstance] getToken];
return NO;
}
return YES;
}
- (void)webView:(WKWebView *)webView
decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
NSURL *url = navigationAction.request.URL;
if ([[IPLLoginManager sharedInstance] isScheme:url.scheme])
{
[IPLLoginManager sharedInstance].resourceSpecifier =
url.resourceSpecifier;
[[IPLLoginManager sharedInstance] getLoadString];
[[IPLLoginManager sharedInstance] getToken];
decisionHandler(WKNavigationActionPolicyCancel);
}
else
{
decisionHandler(WKNavigationActionPolicyAllow);
}
}
3.獲取標(biāo)題
- (void)webViewDidFinishLoad:(UIWebView *)webView{
self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
- (void)webView:(WKWebView *)webView
didFinishNavigation:(WKNavigation *)navigation{
NSLog(@"%@",self.mainWebView.title);
}
4.獲取ua锅风,通過ua區(qū)別PC端還是移動端請求服務(wù)器。
NSString *userAgent = [webView
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSLog(@"old agent :%@", userAgent);
[self.mainWebView evaluateJavaScript:@"navigator.userAgent"
completionHandler:^(id result, NSError *error) {
NSLog(@"%@",result);
}];
實(shí)際上匙隔,只要把自定義的字符串加入ua里面即可~
注:需在請求前設(shè)置
NSString *userAgent = @"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/602.1.46 (KHTML, like Gecko) Mobile/13A137";
NSString *executableFile = @"xxxxx";
NSString *version = [[[NSBundle mainBundle] infoDictionary]
objectForKey:(NSString *)kCFBundleVersionKey];
NSString *ua = [NSString stringWithFormat:@"%@ %@ %@",
executableFile,
version,userAgent];
[[NSUserDefaults standardUserDefaults]
registerDefaults:@{@"UserAgent" : ua, @"User-Agent" : ua}];
[[NSUserDefaults standardUserDefaults] synchronize];
5.清除頁面緩存cookie
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
[storage deleteCookie:cookie];
}
6.添加返回按鈕
1.8 返回添加關(guān)閉按鈕
當(dāng)點(diǎn)擊進(jìn)入兩次以上網(wǎng)頁,想直接返回app熏版,那么就需要一個關(guān)閉按鈕
- (void)leftBarButtonClick:(id)sender
{
if (self.mainwebView.canGoBack)
{
[self.mainwebView goBack];
[self showWebCloseButton];
}
else
{
[self popViewController];
}
}