zoukankan      html  css  js  c++  java
  • UIWebView自定义user agent

    #import "WebViewController.h"

    @interface WebViewController ()<UIWebViewDelegate>

     

    @end

     

    @implementation WebViewController

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

        }

        return self;

    }

     

    +(void)registUserAgent{

       

        static dispatch_once_t onceToken;

        dispatch_once(&onceToken, ^{

            UIWebView *webView=[[UIWebView alloc]init];

            

            

            NSString *oldUA = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];

            

            NSString *newUA = [NSString stringWithFormat:@"%@%@",oldUA,@"你的userAgent"];

            NSDictionary *dictionary = @{@"UserAgent":newUA};

            

            [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

            

           

        });

    }

     

     

    -(void)loadView

    {

        [super loadView];

     

        [WebViewController registUserAgent];

        

    if(!webView)

        {

            webView = [[UIWebView alloc] initWithFrame:self.view.bounds];

            webView.delegate=self;

            if([[[UIDevice currentDevice] systemVersion] floatValue]>6.9)

            webView.frame = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-20);

     

            

            NSString* urlString = @"你的网址";

     

            [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];

        }

        [self.view addSubview:webView];

    }

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

    // Do any additional setup after loading the view.

    }

     

     

    - (void)didReceiveMemoryWarning

    {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    - (void)reload{

        [webView reload];

    }

     

     

    @end

  • 相关阅读:
    wpf arcgis engine 当前没有或未启用Spatial Analyst许可解决办法
    arcglobe 图层三大类说明
    sql自带函数语句
    wpf 前台获取资源文件路径问题
    Microsoft.Office.Interop.Excel的用法
    WPF:父窗口与子窗口的层次关系
    wpf 拖图片到窗体
    wpf comboBox取值问题
    wpf 窗体内容旋转效果 网摘
    js拖动滑块
  • 原文地址:https://www.cnblogs.com/YuFly-lyx/p/6060985.html
Copyright © 2011-2022 走看看