在UIWebView(iPhone SDK)中更改用户代理 [英] Change User Agent in UIWebView (iPhone SDK)

查看:94
本文介绍了在UIWebView(iPhone SDK)中更改用户代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个业务需要能够为嵌入式UIWebView自定义UserAgent。 (例如,如果用户使用某个版本的应用程序而不是另一个版本,则我希望服务器做出不同的响应。)

I have a business need to be able to customize the UserAgent for an embedded UIWebView. (For instance, I'd like the server to respond differently if, say, a user is using one version of the app versus another.)

是否可以自定义在现有iPhone SDK的UIWebView中的UserAgent控制的方式是,对于Windows应用程序中的嵌入式IE浏览器?

Is it possible to customize the UserAgent in the existing iPhone SDK's UIWebView control the way it is, say, for an embedded IE browser in a Windows app?

推荐答案

对于iOS 5更改,我推荐以下方法,最初来自此StackOverflow问题: UIWebView iOS5更改用户代理,如下面的答案中所指出的。

With iOS 5 changes, I recommend the following approach, originally from this StackOverflow question: UIWebView iOS5 changing user-agent as pointed out in an answer below. In comments on that page, it appears to work in 4.3 and earlier also.


通过运行此代码一次,更改UserAgent默认值当你的应用程序启动

Change the "UserAgent" default value by running this code once when your app starts:

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Your user agent", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];


如果您需要的方法版本的iOS 4.3 / 5.0之前。请注意,由于广泛的编辑,本页上的以下评论/其他答案可能没有意义。这毕竟是一个四岁的问题。 ; - )

See previous edits on this post if you need methods that work in versions of iOS before 4.3/5.0. Note that because of the extensive edits, the following comments / other answers on this page may not make sense. This is a four year old question, after all. ;-)

这篇关于在UIWebView(iPhone SDK)中更改用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆