可可:在运行时获取达尔文版本 [英] Cocoa: Get Darwin version at runtime
问题描述
如何在运行时获取 darwin 版本?我知道可以使用 [[NSProcessInfo processInfo] operatingSystemVersion]
获得macOS或iOS版本,但我想要Darwin版本.
How can I get the darwin version at runtime?
I know that I can get the macOS or iOS version using [[NSProcessInfo processInfo] operatingSystemVersion]
, but I want the Darwin version.
There are tables on the internet linking macOS and iOS releases to a darwin version, but i want to implement this future-proof.
推荐答案
使用 uname()
POSIX/BSD库函数.你声明一个 struct utsname
类型的变量并传入它的地址.结构的 release
字段将包含一个带有Darwin版本号的C字符串,例如"16.3.0".如果要将各个组件作为整数,则必须自己解析.
Use the uname()
POSIX/BSD library function. You declare a variable of type struct utsname
and pass in its address. The release
field of the struct will contain a C string with the Darwin version number, such as "16.3.0". If you want the individual components as integers, you'll have to parse it yourself.
这篇关于可可:在运行时获取达尔文版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!