【发布时间】:2012-10-03 12:02:54
【问题描述】:
在我的应用程序中,我使用以下类型的代码来处理用户代理:
// Fake Firefox's user agent during web service's registration
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Mozilla/5.0 (compatible; Windows; U; Windows NT 6.2; WOW64; en-US; rv:12.0) Gecko/20120403211507 Firefox/12.0", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
// Return to standard iOS user agent when web service registration is done
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
我的应用程序的一部分允许用户使用其“注册帐户”页面注册网络服务,这是我能找到的唯一方法来阻止其网站自动启动一个显示“下载我们的应用程序”的页面!”就是这样弄脏用户代理字符串。我已经尝试在NSMutableURLRequest 中设置用户代理,但我根本没有让它工作。 (是的,我尝试在NSMutableURLRequest 中同时设置“User-Agent”和“User_Agent”。)
我听说这可能会导致您的应用被 Apple 拒绝。任何人都可以确认或否认,或提供任何评论吗?谢谢!
【问题讨论】:
-
Google Chrome 会在 iOS 上做到这一点,因为您可以请求网站的桌面版本。
-
为什么要伪造 Firefox?为什么不直接说“MyApp 1.0”等?
标签: ios user-agent