is it possible to request UIWebView using user agent as Safari on iPhone?
i try to request on my application via this url
http://reader.mac.com/mobile/v1/http%3A%2F%2Ffeeds.feedburner.com%2F9To5Mac-MacAllDay
and it also return that it available on iPhone only
how can i fix it?
mycode
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: myurl]];
[urlRequest setValue: @"iPhone" forHTTPHeaderField: @"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) Apple开发者_运维百科WebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"];
[self.myWebView loadRequest:urlRequest];
UIWebView actually resets the user agent of the request just before it loads the URL. So, you may need to do method swizzling to actually change the user agent string that UIWebView loads in. Be warned, method swizzling could be dangerous.
There's a post that has the code for this.
The name of the http header field is User-Agent. Try this:
[urlRequest setValue: @"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"
forHTTPHeaderField: @"User-Agent"];
精彩评论