UIWebView无法加载移动网站

时间:2013-02-22 11:26:16

标签: iphone ios objective-c web uiwebview

我知道之前已经介绍过,但提到的所有方法都不适合我,

我需要UIWebView加载移动网站,而是返回桌面版

我试过

NSMutableURLRequest *stadiumURLRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.example.com/"]];
[stadiumURLRequest setValue:@"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3" forHTTPHeaderField:@"User-Agent"];
[stadiumWebView loadRequest:stadiumURLRequest];

并在AppDelegate中:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
[cookieProperties setObject:@"mobileApp" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"1" forKey:NSHTTPCookieValue];
[cookieProperties setObject:@"www.example.com" forKey:NSHTTPCookieDomain];
[cookieProperties setObject:@"www.example.com" forKey:NSHTTPCookieOriginURL];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];

NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
}

由于

1 个答案:

答案 0 :(得分:0)

你不必添加标题,它们是默认发送的,也可以看看它是否在safari中加载而不仅仅是网站问题