Ping
Ping

Reputation: 155

How would I get the other app's version from mac app

How would I get the other app's version. I can use [NSWorkspace fullPathForApplication:(NSString *)appName] to get app's path, can I get the app's info?

Upvotes: 2

Views: 297

Answers (2)

l'L'l
l'L'l

Reputation: 47169

There's several ways you can accomplish this — I usually take the shortest route using NSBundle in addition to CFBundleversion:

NSBundle *appBundle = [NSBundle bundleWithPath:appPath];
NSString *bundleVersion = [appBundle objectForInfoDictionaryKey:@"CFBundleVersion"];

Upvotes: 1

trojanfoe
trojanfoe

Reputation: 122391

Once you have the full path to the Application, you can read the Contents/Info.plist file and look at the CFBundleShortVersionString value.

Something like this:

NSString *appPath = [NSWorkspace fullPathForApplication:appName];
NSString *plistPath = [appPath stringByAppendingPathComponent:@"Contents/Info.plist"];
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSString *version = plist[@"CFBundleShortVersionString"];

Upvotes: 1

Related Questions