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 interpretation 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With