我目前正在使用Mono在C#中編寫Mac OSX應用程序。 我想要做的是確定程序運行的OSX版本。如何訪問本機Objective C屬性?
我找到了適合我需求的常數NSAppKitVersionNumber
。
但是,我不知道如何訪問它...
我相信這是可能的,因此你的任何幫助,將不勝感激!
我目前正在使用Mono在C#中編寫Mac OSX應用程序。 我想要做的是確定程序運行的OSX版本。如何訪問本機Objective C屬性?
我找到了適合我需求的常數NSAppKitVersionNumber
。
但是,我不知道如何訪問它...
我相信這是可能的,因此你的任何幫助,將不勝感激!
在Windows上的.NET中,您有Environment.OSVersion方法。你可以嘗試一下,看看是什麼讓你在Mac OS:
// Sample for the Environment.OSVersion property
using System;
class Sample
{
public static void Main()
{
Console.WriteLine();
Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());
}
}
/*
This example produces the following results:
OSVersion: Microsoft Windows NT 5.1.2600.0
*/
事情是這樣的:
[DllImport("/System/Library/Frameworks/CoreServices.framework/CoreServices")]
internal static extern short Gestalt(int selector, ref int response);
static string m_OSInfoString = null;
static void InitOSInfoString()
{
//const int gestaltSystemVersion = 0x73797376;
const int gestaltSystemVersionMajor = 0x73797331;
const int gestaltSystemVersionMinor = 0x73797332;
const int gestaltSystemVersionBugFix = 0x73797333;
int major = 0;
int minor = 0;
int bugFix = 0;
Gestalt(gestaltSystemVersionMajor, ref major);
Gestalt(gestaltSystemVersionMinor, ref minor);
Gestalt(gestaltSystemVersionBugFix, ref bugFix);
if (major == 10 && minor == 5)
RunningOnLeopard = true;
else
{
RunningOnLeopard = false;
if (major == 10 && minor == 7)
RunningOnLion = true;
}
m_OSInfoString = string.Format("Mac OS X/{0}.{1}.{2}", major, minor, bugFix);
}
謝謝,您的解決方案也適用,但我發現一個oneliner,也解決了我的問題,請在下面的帖子下看到我的評論 – wojtuch
在我的山獅'Environment.OSVersion'回報 「的Unix 12.2.0.0」 - 與這個http://stackoverflow.com/a/11697362/183422你應該能夠拼湊一些東西。 –
非常感謝您的提示,我解決它如下: 'bool CanUseUserNotificationCenter = Environment.OSVersion.Version.Major> = 12;' – wojtuch