iPad 2 检测
由于我没有 iPad 2,因此我需要知道调用 [[UIDevice currentDevice] model] 时它返回什么。我以为它只返回“iPad”,但看来我错了。
有人可以告诉我吗?
谢谢
Since I don't have iPad 2, I need to know what it returns when calling [[UIDevice currentDevice] model]. I thought it returns just "iPad" but it seems I'm wrong.
Can somebody let me know?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
首先我应该提到,我花了很多时间才弄清楚为什么 ipad 模拟器“说”它是 iphone。对我来说,事实证明我只需将其切换为通用:
这是我认为的代码是相当典型的检测代码。还有其他一些可能也有效,但是......
First off I should mention that it took me a great deal of time to figure out why the ipad simulator was "saying" it was iphone. For me, it turned out I just had to switch it over to universal:
Here's the code which I think is fairly typical detection code for this. There are others that probably work too but...
您可以从以下网站获取所有iPad2退货型号或您想要的iOS设备型号:
IOS 设备型号和平台
您也可以使用以下代码直接检索型号:
You can get all IPad2 return model or the model of the iOS device that you want from the following website:
IOS Devices Models and Platforms
Also you can use the following code to retrieve the model direct:
您在这里得到了很多答案,其中阐述了为什么您不应该这样做的意见,并为您提供了替代代码,但您没有得到问题的任何实际答案。如果您想准确确定您正在哪个设备上运行(无论您想要什么目的......不要让其他开发人员假装知道您想要完成什么),您可以使用 < code>UIDeviceHardware 第三方类。您可以在这里找到它:
https://github.com/fahrulazmi/UIDeviceHardware
您只需调用:
并且它将返回设备。在您的情况下,您需要将
platformString
与以下任何一个相匹配:You are getting a lot of answers on here that state opinions on why you shouldn't be doing this and are giving you alternative code, but you aren't getting any actual answers to your question. If you want to determine exactly which device you are running on (for whatever purpose you want... don't let other developers pretend to know what you are trying to accomplish), you can using the
UIDeviceHardware
third-party class. You can find it here:https://github.com/fahrulazmi/UIDeviceHardware
You'll simply call:
And it will return the device. In your case, you'd be looking to match the
platformString
to any of these:检查是否有带摄像头的 iPad。
请注意,通常最好检测特定功能,而不是基于模型/版本检测进行全面假设。例如,如果您需要相机,则明确测试相机;如果您需要根据可用 RAM 量调整 UI 质量,测试物理 RAM;等。另请注意我写的评论强调了使用的危险模型检测。
Check for an iPad with a camera.
Note that it is generally better to detect specific features rather than make blanket assumptions based on model/version detection. For instance, if you need a camera, then test for the camera explicitly; if you need to tweak the UI quality based on the amount of RAM available, test for physical RAM; etc. Also note a comment I wrote that highlights the dangers of using model detection.
切勿将
model
属性用于除显示信息或诊断输出之外的任何其他用途。它不能保证被保留,如果您依赖它,您就不必要地在新设备到来时切断它们。许多 iPhone 应用程序无法在 iPad 的兼容模式下使用,只是因为它们检查了
model
属性,如果不是 iPhone / iPod,它们就不会执行任何操作。Never use the
model
property for anything else than displaying it for informational purposes or diagnostics output. It is not guaranteed to be preserved and if you rely on it, you unnecessarily cut off new devices as they come.Lots of iPhone apps could not be used in the compatibility mode of iPad just because they checked the
model
property and if it wasn't iPhone / iPod they didn't do anything.要获得精确的型号字符串,例如“iPad2,2”,您可以使用类似的字符串。
To get the precise model string, e.g. "iPad2,2", you could use something like this.
UIScreen+Retina.h
#import
UIScreen+Retina.m
用法
//http://stackoverflow.com/questions/3294100/how-to-
Differentiate- Between-iphone4-and-iphone-3 IPAD/IPHONE 高分辨率/低分辨率
UIScreen+Retina.h
#import
UIScreen+Retina.m
USAGE
//http://stackoverflow.com/questions/3294100/how-to-differentiate-between-iphone4-and-iphone-3
IPAD/IPHONE HIGH/LOW RES
我想你可以测试一下规模
I think you can test it scale
如果您使用 OpenGL,您可以查看 GPU 模型。 iPad 1 配备 PowerVR SGX 535,iPad 2 配备 PowerVR SGX 543。
If you're using OpenGL you can look at the GPU model. iPad 1 has a PowerVR SGX 535 and iPad 2 has a PowerVR SGX 543.
UIDevice 类参考 应该有所帮助。如需更具体的解决方案,请尝试这个SO问题。
至于你的第二个问题,测试分辨率的最佳方法是获取与iPad3,1的PPI数相似的显示器。不幸的是,您可能无法做到。测试任何应用程序的最佳方法是在实际设备上。
UIDevice Class Reference should help. For more specific solutions, try this SO question.
As for your second question, the best way to test the resolution would be to acquire a display similar to the number of PPI of the iPad3,1. Unfortunately, you probably won't be able to. The best way to test any app is on the actual device.
此行将打印设备版本:
Ipad 1: Platform: iPad1,1
Ipad 2: Platform: iPad2,1
Ipad 3: Platform: iPad3,3
Iphone 4S: Platform: iPhone4,1
Simulator: Platform: x86_64
This lines will print the device version:
Ipad 1: Platform: iPad1,1
Ipad 2: Platform: iPad2,1
Ipad 3: Platform: iPad3,3
Iphone 4S: Platform: iPhone4,1
Simulator: Platform: x86_64