[英]Simple code to get type of Mac that's hosting app? i.e. “MacBook Pro (Retina, 15-inch, Late 2013)”
I'm looking for some short code to just catch the type of mac (in descriptive string format) that my Obj-C app is running on. 我正在寻找一些简短的代码来捕获运行我的Obj-C应用程序的mac类型(以描述性的字符串格式)。
Like: 'MacBook Pro (Retina, 15-inch, Late 2013)' 喜欢:'MacBook Pro(Retina,15英寸,2013年末)
thanks 谢谢
It's not too bad, but you will have to use a bit of C. This answer is taken from an excellent blog post about the subject at http://joris.kluivers.nl/blog/2013/11/28/model-identifiers/ . 这不是太糟糕,但你必须使用一点C.这个答案取自http://joris.kluivers.nl/blog/2013/11/28/model-identifiers上关于这个主题的优秀博客文章。 / 。 The gist of it is that you use
sysctlbyname()
to find the model identifier like MacBookPro8,2
, then translate it to a human readable string. 它的要点是,你使用
sysctlbyname()
找到像模型标识MacBookPro8,2
,然后将其转换为人类可读的字符串。 This snippet creates the model identifier: 此代码段创建模型标识符:
#include <sys/types.h>
#include <sys/sysctl.h>
size_t size;
sysctlbyname("hw.model", NULL, &size, NULL, 0);
char *model = malloc(size);
sysctlbyname("hw.model", model, &size, NULL, 0);
NSLog(@"%s", model); // You would probably copy it to a NSString for later use
free(model);
Once you have that string as an NSString
, there's unfortunately not a built in way to convert between the identifier and a nicely displayed name. 一旦你将该字符串作为
NSString
,遗憾的是没有内置的方法来转换标识符和一个很好地显示的名称。 But I found this site http://www.everymac.com/systems/by_capability/mac-specs-by-machine-model-machine-id.html , that seems to have all mac models you could possibly want, updated, with a simple translation between the name and the identifier. 但我发现这个网站http://www.everymac.com/systems/by_capability/mac-specs-by-machine-model-machine-id.html ,似乎有你可能想要的所有mac模型,更新,名称和标识符之间的简单转换。 You'd have to do a bit of work to put that into a file, but shouldn't be too bad.
你必须做一些工作把它放到一个文件中,但不应该太糟糕。 Hope that helps!
希望有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.