xcode 如何检查设备是否为 iPad 3?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9793509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how do I check if the device is iPad 3?
提问by AbhinavVinay
Possible Duplicate:
Detecting iPad 3 vs iPad 2 device?
Programmatically detect an iPad 3 (HD)?
I am making an iPad app and want to know if the app is running in an iPad 2 or 3 so accordingly I can perform some action.
我正在制作一个 iPad 应用程序,想知道该应用程序是在 iPad 2 还是 iPad 3 上运行,因此我可以执行一些操作。
What would be the best way to find this?
找到这个的最好方法是什么?
I am currently using
我目前正在使用
NSString *platform = [[UIDevice currentDevice] platformString];
But it returns "Unknown iPad" when I run on iPad 3.
但是当我在 iPad 3 上运行时它返回“Unknown iPad”。
回答by rickster
It's generally best to check for the device features you're interested in rather than looking for a specific model of device. Apple recommends this, and for good reason: if you design for features of the new iPad, your customers won't be happy if Apple releases another device with those features and your app doesn't support them.
通常最好检查您感兴趣的设备功能,而不是寻找特定型号的设备。Apple 建议这样做,并且有充分的理由:如果您针对新 iPad 的功能进行设计,如果 Apple 发布具有这些功能的另一台设备而您的应用程序不支持它们,您的客户将不会高兴。
If you need to determine whether you're on an iPad, check UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
. If you need to see if you have a Retina display, check [UIScreen mainScreen].scale
. Combine the two and you can find out if you're on an iPad with Retina display.
如果您需要确定您是否使用 iPad,请检查UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
。如果您需要查看是否有 Retina 显示屏,请检查[UIScreen mainScreen].scale
。将两者结合起来,您就可以确定您是否使用的是配备 Retina 显示屏的 iPad。
If you need other features specific to the new iPad, look in the API for those features: AV Foundation can tell you about the capabilities of the built-in camera, for example. There's probably some way to check for LTE, too, but I'm not aware of it.
如果您需要特定于新 iPad 的其他功能,请查看这些功能的 API:例如,AV Foundation 可以告诉您有关内置摄像头的功能。也可能有一些方法可以检查 LTE,但我不知道。