UIWebView 追加UA信息

来源:互联网 发布:淘宝买家退货率高 编辑:程序博客网 时间:2024/06/07 22:15

UIWebView 追加UA信息

//  UIWebView+processwebViewUserAgent.m// ////  Created by devzkn on 18/09/2017.//  Copyright © 2017. All rights reserved.//#import "UIWebView+processwebViewUserAgent.h"@implementation UIWebView (processwebViewUserAgent)/** 先创建一个UIWebView,设置UA,然后删掉它,重新创建你需要的UIWebView */+(void)load{    [self processwebViewUserAgentWithAppendingString:[NSString stringWithFormat:@"gyq_iphone%@",WLAPIVersion1]];}+ (void)processwebViewUserAgentWithAppendingString:(NSString*)appendingString{    //get the original user-agent of webview    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];    NSString *oldAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];    NSLog(@"old agent :%@", oldAgent);    //add my info to the new agent    NSString *newAgent = [oldAgent stringByAppendingString:appendingString];    NSLog(@"new agent :%@", newAgent);    //regist the new agent    NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent", nil];    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];}

获取当前页面的title

      self.title= [webView stringByEvaluatingJavaScriptFromString:@"document.title"];//获取当前页面的title
self.currentURL = webView.request.URL.absoluteString;      NSLog(@"title-%@--url-%@--",self.title,self.currentURL);     NSString *lJs = @"document.documentElement.innerHTML";//获取当前网页的html     self.currentHTML = [webView stringByEvaluatingJavaScriptFromString:lJs]; 

//去除webView底部的黑条

      _webView.opaque = NO;        _webView.backgroundColor = [UIColor clearColor];