简体   繁体   English

简单的代码,以获得托管应用程序的Mac类型? 即“MacBook Pro(Retina,15英寸,2013年末)”

[英]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.

相关问题 在iOS 7(4英寸视网膜显示屏)上运行应用程序时显示黑条 - Black bars showing when running app on iOS 7 (4 inch retina display) 此代码仅适用于iPhone Retina 4英寸模拟器 - This code only works on iPhone Retina 4-inch simulator 有没有办法让Xcode的调试器在本地时区显示日期(即,不是UTC)? - Is there a way to get Xcode's debugger to show dates in local timezone (i.e., not UTC)? 在iOS 7下,如何使UITextView的高度取决于运行应用程序的设备的类型(4英寸屏幕vs 3.5) - Under iOS 7, how do I make my UITextView's height dependent on the type of device running the app (4 inch screen vs 3.5) 实现具有不同部分的UIScrollView(即Yahoo! Weather应用) - Implement a UIScrollView with different sections (i.e. Yahoo! Weather app) 如何以编程方式确定 OS X 上 Retina MacBook Pro 屏幕的原始像素分辨率? - How to programmatically determine native pixel resolution of Retina MacBook Pro screen on OS X? 应用程序的隔离/沙盒部分(即插件) - Isolate/sandbox part (i.e. plugin) of app 获取NSView的布局框架(即ibLayoutInset) - Get layout frame of NSView (i.e. ibLayoutInset) iPhone 5视网膜4英寸触摸屏 - iPhone 5 retina 4 inch touch screen 什么是可以与Mac上的Objective-C一起使用的良好报告生成(即PDF报告)? - What is a good report generation (i.e. PDF reports) that can be used with Objective-C on mac?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM