【问题标题】:UIWebView set user-agent at run time [duplicate]UIWebView 在运行时设置用户代理 [重复]
【发布时间】:2012-08-23 16:29:29
【问题描述】:

可能重复:
UIWebView iOS5 changing user-agent

有些网站需要在桌面版和移动版中打开。如何在 UIWebView 的委托“webView:shouldStartLoadWithRequest:navigationType”中设置不同的用户代理。提前致谢。

【问题讨论】:

    标签: iphone uiwebview


    【解决方案1】:

    【讨论】:

    • 王子感谢您的回复。是否可以在运行时更改用户代理?
    • 是的,可以在运行时更改用户代理 - (BOOL)webView:(UIWebView *)aWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    • - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)req navigationType:(UIWebViewNavigationType)Type { NSString *url = [[req URL] absoluteString]; NSString *userAgent = [url rangeOfString:@"yahoo.com"].location != NSNotFound ? @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7" : mUserAgent; NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:userAgent, @"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];返回是; }
    • 这段代码有问题吗?
    • 这对于 App Store 接受是否安全?谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    • 2017-05-06
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    相关资源
    最近更新 更多