How to know what Mac OS the app is running on?

后端 未结 7 2015
遥遥无期
遥遥无期 2020-12-31 18:30

I\'ve seen in some projects something like:

#if .....
    code...
#endif

but i can\'t find it now...
Let\'s say, for example, if the ap

7条回答
  •  误落风尘
    2020-12-31 19:01

    You can get the current release from the uname -r command (that's actually the kernel release, though it's easy to map onto Mac OS X versions), from the sw_vers command which gives you the release name, version and build identifier, or from the Gestalt() function (on current versions of Mac OS X, anyway). The safest way is probably to read the output of sw_vers which is in a stable format that's easy to parse.

    Notice that you probably don't want to know what version of the OS you're on, though. What you probably want to do is to test whether a particular feature is available. You can do this by weak-linking frameworks, by weak class references, or by inspecting whether a class responds to selectors appropriate to the feature you're interested in.

提交回复
热议问题