我知道这之前已经涵盖了,但是提到的方法都不适用于我,
我需要 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];
}
谢谢
最佳答案
您不必添加 header ,它们是默认发送的,另外,看看它是否在 safari 中加载,而不仅仅是网站问题