LoginSignup
11
12

More than 5 years have passed since last update.

OS X のバージョン番号を取得する

Last updated at Posted at 2012-12-26

http://cocoadev.com/wiki/DeterminingOSVersion によれば、 OS X のバージョンを取得する正しい方法は /System/Library/CoreServices/SystemVersion.plistProductVersion キーを参照することらしい。

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
NSString *version = [dict objectForKey:@"ProductVersion"];
// version == "10.8.2"

Gestalt() で取得することもできるが、この関数は10.8から非推奨になった。

 SInt32 major, minor, bugFix;
 Gestalt(gestaltSystemVersionMajor, &major);
 Gestalt(gestaltSystemVersionMinor, &minor);
 Gestalt(gestaltSystemVersionBugFix, &bugFix);
// major  == 10
// minor  == 8
// bugFix == 2

Human readable な文字列が欲しければ -[NSProcessInfo operatingSystemVersionString] が使える。

NSString *version = [[NSProcessInfo processInfo] operatingSystemVersionString];
// version == "Version 10.8.2 (Build 12C60)"
11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12