如何从mac应用程序获取其他应用程序的版本
问题描述:
如何获取其他应用程序的版本? 我可以使用[NSWorkspace fullPathForApplication:(NSString *)appName]来获取应用程序的路径,我可以获取应用程序的信息吗?如何从mac应用程序获取其他应用程序的版本
答
有几种方法可以做到这一点 - 我通常采取除了使用NSBundle
最短路线CFBundleversion
:
NSBundle *appBundle = [NSBundle bundleWithPath:appPath];
NSString *bundleVersion = [appBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
答
一旦你有了应用程序的完整路径,你可以阅读Contents/Info.plist
文件并查看CFBundleShortVersionString
的值。
事情是这样的:
NSString *appPath = [NSWorkspace fullPathForApplication:appName];
NSString *plistPath = [appPath stringByAppendingPathComponent:@"Contents/Info.plist"];
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSString *version = plist[@"CFBundleShortVersionString"];
很好的答案最好的,我得到了更多比我想要的。 – Ping 2014-09-05 14:02:53