I want to get the OS X system version, such as: 10.5.4, 10.4.8, etc. I want to get it in my app, how do I do this? Thanks!
我想获得OS X系统版本,例如:10.5.4,10.4.8等。我想在我的应用程序中获取它,我该怎么做?谢谢!
8 个解决方案
#1
You can read the property list at "/System/Library/CoreServices/SystemVersion.plist and extract the "ProductVersion" key, this is how the OS X installer application does it. Here's an example:
您可以在“/System/Library/CoreServices/SystemVersion.plist中读取属性列表并提取”ProductVersion“键,这是OS X安装程序应用程序的工作方式。这是一个示例:
NSString *versionString;
NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
versionString = [sv objectForKey:@"ProductVersion"];
Alternatively, the command swvers -productVersion
will do the same.
或者,命令swvers -productVersion也会这样做。
#2
You can use Gestalt:
你可以使用Gestalt:
SInt32 version = 0;
Gestalt( gestaltSystemVersion, &version );
BOOL leopard = ( version >= 0x1050 );
if ( leopard )
{
//draw it this way
}
else
{
//draw it that way
}
Keep in mind if you're checking if a method is available or not, it's better to test that directly using respondsToSelector:.
请记住,如果您正在检查方法是否可用,最好使用respondsToSelector直接测试:
#3
NSString *osver()
{
SInt32 versionMajor=0, versionMinor=0, versionBugFix=0;
Gestalt(gestaltSystemVersionMajor, &versionMajor);
Gestalt(gestaltSystemVersionMinor, &versionMinor);
Gestalt(gestaltSystemVersionBugFix, &versionBugFix);
return [NSString stringWithFormat:@"%d.%d.%d", versionMajor, versionMinor, versionBugFix];
}
#4
-[NSProcessInfo operatingSystemVersionString]
is human readable and localized. Appropriate for displaying to user or using in bug emails and such, but not appropriate for parsing.
- [NSProcessInfo operatingSystemVersionString]是人类可读和本地化的。适合显示给用户或使用错误电子邮件等,但不适合解析。
#5
Again, you can use Gestalt. Look at the documentation for more information; specifically, you'll want to pass the gestaltSystemVersionMajor
, gestaltSystemVersionMinor
, and gestaltSystemVersionBugFix
constants in the "System Version Constants" portion of the Gestalt Manager Reference documentation
同样,您可以使用Gestalt。查看文档以获取更多信息;具体来说,您需要在Gestalt Manager参考文档的“系统版本常量”部分中传递gestaltSystemVersionMajor,gestaltSystemVersionMinor和gestaltSystemVersionBugFix常量
#6
There's also a Cocoa wrapper around the Gestalt calls others have mentioned in the Google Toolbox for Mac: http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMSystemVersion.h
其他人在Google Toolbox for Mac中提到的Gestalt调用还有一个Cocoa包装器:http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMSystemVersion.h
#7
use this method it will return Mac OS X version
使用此方法将返回Mac OS X版本
+(SInt32) OSVersion;
{
SInt32 osxMinorVersion;
Gestalt(gestaltSystemVersionMinor, &osxMinorVersion);
return osxMinorVersion;
}
#8
After 10_10, 8_0 were presented the better & simplest way would be[NSProcessInfo processInfo].operatingSystemVersion
which will returnNSOperatingSystemVersion
struct
with all 3 numbers.
在10_10之后,8_0呈现了更好和最简单的方式[NSProcessInfo processInfo] .operatingSystemVersion将返回带有所有3个数字的NSOperatingSystemVersion结构。
#1
You can read the property list at "/System/Library/CoreServices/SystemVersion.plist and extract the "ProductVersion" key, this is how the OS X installer application does it. Here's an example:
您可以在“/System/Library/CoreServices/SystemVersion.plist中读取属性列表并提取”ProductVersion“键,这是OS X安装程序应用程序的工作方式。这是一个示例:
NSString *versionString;
NSDictionary * sv = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
versionString = [sv objectForKey:@"ProductVersion"];
Alternatively, the command swvers -productVersion
will do the same.
或者,命令swvers -productVersion也会这样做。
#2
You can use Gestalt:
你可以使用Gestalt:
SInt32 version = 0;
Gestalt( gestaltSystemVersion, &version );
BOOL leopard = ( version >= 0x1050 );
if ( leopard )
{
//draw it this way
}
else
{
//draw it that way
}
Keep in mind if you're checking if a method is available or not, it's better to test that directly using respondsToSelector:.
请记住,如果您正在检查方法是否可用,最好使用respondsToSelector直接测试:
#3
NSString *osver()
{
SInt32 versionMajor=0, versionMinor=0, versionBugFix=0;
Gestalt(gestaltSystemVersionMajor, &versionMajor);
Gestalt(gestaltSystemVersionMinor, &versionMinor);
Gestalt(gestaltSystemVersionBugFix, &versionBugFix);
return [NSString stringWithFormat:@"%d.%d.%d", versionMajor, versionMinor, versionBugFix];
}
#4
-[NSProcessInfo operatingSystemVersionString]
is human readable and localized. Appropriate for displaying to user or using in bug emails and such, but not appropriate for parsing.
- [NSProcessInfo operatingSystemVersionString]是人类可读和本地化的。适合显示给用户或使用错误电子邮件等,但不适合解析。
#5
Again, you can use Gestalt. Look at the documentation for more information; specifically, you'll want to pass the gestaltSystemVersionMajor
, gestaltSystemVersionMinor
, and gestaltSystemVersionBugFix
constants in the "System Version Constants" portion of the Gestalt Manager Reference documentation
同样,您可以使用Gestalt。查看文档以获取更多信息;具体来说,您需要在Gestalt Manager参考文档的“系统版本常量”部分中传递gestaltSystemVersionMajor,gestaltSystemVersionMinor和gestaltSystemVersionBugFix常量
#6
There's also a Cocoa wrapper around the Gestalt calls others have mentioned in the Google Toolbox for Mac: http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMSystemVersion.h
其他人在Google Toolbox for Mac中提到的Gestalt调用还有一个Cocoa包装器:http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMSystemVersion.h
#7
use this method it will return Mac OS X version
使用此方法将返回Mac OS X版本
+(SInt32) OSVersion;
{
SInt32 osxMinorVersion;
Gestalt(gestaltSystemVersionMinor, &osxMinorVersion);
return osxMinorVersion;
}
#8
After 10_10, 8_0 were presented the better & simplest way would be[NSProcessInfo processInfo].operatingSystemVersion
which will returnNSOperatingSystemVersion
struct
with all 3 numbers.
在10_10之后,8_0呈现了更好和最简单的方式[NSProcessInfo processInfo] .operatingSystemVersion将返回带有所有3个数字的NSOperatingSystemVersion结构。