使用IBM MobileFirst Platform 7.0我无法修改UIWebView的用户代理。我有一个混合应用程序(HTML / CSS,JS,Objective-C)并尝试了UIWebView iOS5 changing user-agent(问答版本):
@implementation MyAppDelegate
+ (void)initialize
{
NSString* useragent = @"Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0";
NSLog(@"Setting User-Agent to: %@", useragent);
NSDictionary* dictionary = [NSDictionary dictionaryWithObjectsAndKeys:useragent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
}
(...)
和/或
(...)
[request setValue:@"Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0" forHTTPHeaderField:@"User-Agent"];
[webView loadRequest: request];
NSLog(@"Getting UA: %@", [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"]);
(...)
但我的输出是:
Getting UA: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20130401 Firefox/31.0/Worklight/7.0.0.0
我试图在配置的某个地方找到这个令牌,但是不成功......
我可以通过将以上代码添加到IBM Example, project "IncludeExternalPages"来重现这一点。如果有帮助,我会很乐意提供代码。
答案 0 :(得分:0)
这可能在技术上是可行的,但请注意,MobileFirst Platform的框架依赖于它提供的默认使用者,因此不建议您更改它。
你应该问问自己:
答案 1 :(得分:0)
好的,唯一有用的是使用:
i)个
NSString* useragent = @"Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0";
NSLog(@"Setting User-Agent to: %@", useragent);
NSDictionary* dictionary = [NSDictionary dictionaryWithObjectsAndKeys:useragent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
ⅱ)
在AppDelegate中wlInitDidCompleteSuccessfully
的开头
ⅲ) 卸载并重新安装应用程序后