加载桌面版网站 [英] Load Desktop version of web sites

查看:191
本文介绍了加载桌面版网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何加载桌面版网站(例如google,facebook)而不是移动版?

How can I load desktop versions of web sites(such as google, facebook) rather than mobile versions?

推荐答案

编辑:忽略这一切。 Yaniv是对的。只需使用 - loadRequest NSMutableURLRequest 加载到 UIWebView 实例c>消息并将User-Agent标题设置为您想要的任何内容。

Disregard all this. Yaniv's right. Just load an NSMutableURLRequest to the UIWebView instance using the - loadRequest: message and set the "User-Agent" header to whatever you want.

NSMutableURLRequest *rq = [NSMutableURLRequest requestWithURL:someUrl];
[rq setValue:@"Some desktop user-agent" forHTTPHeaderField:@"User-Agent"];
[webView loadRequest:rq];

对于您的信息,桌面用户代理字符串的一个很好的选择是Chrome的 - 它也是基于WebKit,作为Safari,因此WebKit特定的扩展将起作用。因此,尝试将用户代理字符串设置为

For your information, a good choice for a desktop user-agent string is that of Chrome - it's also WebKit-based, as Safari, so WebKit-specific extensions will work. So try setting the user-agent string to


Mozilla / 5.0(Macintosh; Intel Mac OS X 10_8_2)AppleWebKit / 537.11(KHTML,类似Gecko)Chrome / 23.0.1271.6 Safari / 537.11

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11






原帖:


Original post:

您可以尝试欺骗UIWebView的用户代理,但我不能保证这样一个强大的黑客会让您通过AppStore的瘦门......

You can try spoofing the user agent of UIWebView but I can't guarantee that such a fat hack will let you through the thin gate of AppStore...

void *object_getIvarPtr(id obj, const char *name)
{
    Ivar iv = object_getInstanceVariable(obj, name, NULL);
    off_t offset = ivar_getOffset(iv);
    return (char *)obj + offset;
}

// In some initialization routine, after having created the web view
id webViewInternal = *(id *)object_getIvarPtr(someWebView, "_internal");
id webBrowserView = *(id *)object_getIvarPtr(webViewInternal, "browserView");
id webKitWebView = [webBrowserView webView];

NSString *desktopUAStr = @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.6 Safari/537.11"
[webKitWebView setCustomUserAgent:desktopUAStr];

这篇关于加载桌面版网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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