Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get webkit version in cocoa

Tags:

cocoa

webkit

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 ?

like image 968
MatterGoal Avatar asked Aug 29 '11 10:08

MatterGoal


2 Answers

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.

like image 120
Rob Keniger Avatar answered Oct 18 '22 22:10

Rob Keniger


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
like image 41
Julian F. Weinert Avatar answered Oct 18 '22 20:10

Julian F. Weinert