如何从Cocoa Objective-C应用程序中找到Mac OS X的版本号(例如“10.6.7”)?
答案 0 :(得分:25)
#import <CoreServices/CoreServices.h>
SInt32 major, minor, bugfix;
Gestalt(gestaltSystemVersionMajor, &major);
Gestalt(gestaltSystemVersionMinor, &minor);
Gestalt(gestaltSystemVersionBugFix, &bugfix);
NSString *systemVersion = [NSString stringWithFormat:@"%d.%d.%d",
major, minor, bugfix];
答案 1 :(得分:18)
您可以使用Apple代码使用的相同技术......
NSDictionary *systemVersionDictionary =
[NSDictionary dictionaryWithContentsOfFile:
@"/System/Library/CoreServices/SystemVersion.plist"];
NSString *systemVersion =
[systemVersionDictionary objectForKey:@"ProductVersion"];
Apple正是这样填写函数_CFCopySystemVersionDictionary
中各种系统实用程序的版本号:
答案 2 :(得分:11)
对于OS X 10.10+,我认为使用NSProcessInfo
是一种更简单,更安全的方法:
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
NSLog([NSString stringWithFormat:@"%ld.%ld.%ld", version.majorVersion, version.minorVersion, version.patchVersion]);