Get webkit version in cocoa
I'm working on OSX application that needs a CSS preview. I need to find a way to differentiate users with safari 5.0 from users with safari 5.1 because webkit preview has many differences in this 2 versions. For example, the gradient radial interpret开发者_运维问答ation is totally different!
Is there a way to intercept the webkit version ?
You can get the user-agent string for the current WebKit version using JavaScript. Just do something like this:
NSString* userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
which will produce something like this:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.14 (KHTML, like Gecko)
You can then parse the user-agent string to get the version of WebKit in use.
This helps you getting the WebKit version before loading the request so you could probably put together your own user agent. So this solution is better:
NSBundle *webKit = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"];
NSString *version = [[webKit infoDictionary] objectForKey:@"CFBundleVersion"];
if (webKit && [webKit load]) {
NSLog(@"%@", [webKit infoDictionary]);
}
[webKit unload]; // you might also unload the bundle, if you don't need it later
精彩评论