开发者

Display web content in iPhone app's web view with different stylesheet than in Mobile Safari

What is the best way to display the same web page dif开发者_StackOverflow社区ferently between Mobile Safari and a WebView inside an iPhone app? (It seems both would have the same user agent so how else can I detect the difference?)


They have different user agents. According to whatismyuseragent.com,

Safari: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-gb) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5

UIWebView: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-gb) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8C148

The differences are "Version/5.0.2" (corresponding to the marketing version of Mac Safari) and "Safari/6533.18.5" (corresponding to the Safari build number). I'm not sure why Mobile/8C148 (corresponding to iOS 4.2.1) is in the middle of both.

Additionally, you can set the user agent used by UIWebView by "swizzling" -[NSMutableURLRequest setValue:forHTTPHeaderField:] or (probably) overriding -[NSURLRequest valueForHTTPHeaderField]. How to achieve this is an exercise to the reader.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜