C# 如何访问本机Objective C属性?
我目前正在使用Mono为MacOSX编写一个C#应用程序。 我想做的是确定程序运行的OSX版本 我找到了符合我需要的常量C# 如何访问本机Objective C属性?,c#,objective-c,macos,mono,monomac,C#,Objective C,Macos,Mono,Monomac,我目前正在使用Mono为MacOSX编写一个C#应用程序。 我想做的是确定程序运行的OSX版本 我找到了符合我需要的常量NSAppKitVersionNumber 但是,我不知道如何访问它 我相信这是可能的,因此您的任何帮助都将不胜感激 在windows上的.NET中,您有Environment.OSVersion方法。您可以试试它,看看它在Mac OS上给您带来了什么: // Sample for the Environment.OSVersion property using System
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);
}
在我的Mountain Lion
环境中。OSVersion
返回“Unix 12.2.0.0”-通过它,您应该能够拼凑出一些东西。非常感谢您的提示,我按照以下方式解决了它:bool CanUseUserNotificationCenter=Environment.OSVersion.Version.Major>=12代码>谢谢,您的解决方案也适用,但我发现一个oneliner也解决了我的问题,请参阅下面帖子下的我的评论