如何获取 iPhone 设备类型?
我想获取 iphone 设备类型,如果它是 xcode 4.0 中的 iphone 2 或 3G 或 4。
有什么办法可以得到吗?
如果是的话,请告诉我。
I want to get iphone device type if it is iphone 2 or 3G or 4 in xcode 4.0.
Is there any way to get it?
If it is, please tell me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我发现了一些新的算法来获取设备类型和 iOS 版本。
I found some new algorithm to get device type and iOS version.
实际上,
UIDevice
类没有方法platformString
。如果使用未记录的方法,您的应用程序将被 Apple 拒绝。会成功的。
Actually, the
UIDevice
class does not have a methodplatformString
. With undocumented methods your app will get rejected by Apple.will do the trick.
Caleb 是对的,您不应该检查设备类型,而应该检查功能。例如,您可以检查设备是否支持多任务,如下所示:
如果必须,您可以检查 iOS 版本,但要知道这不能替代检查对象是否
respondsToSelector:
。据我所知,没有记录的方法来检查设备型号。
Caleb is right, you shouldn't check for device type, but for functionality. For example, you can check whether the device supports multitasking like so:
If you must, you can check the iOS version, but know this is not a substitute for checking whether an object
respondsToSelector:
.As far as I know, there is no documented way to check the device model.
我在我的项目中添加了一个静态方法来检查设备类型:iPad、iPhone4(或更低)和iPhone5,以处理不同的屏幕尺寸。
您还可以使用 UIUserInterfaceIdiomPad 类型。
据我所知,iPod 和 iPhone 的目的是平等对待。但如果您需要确定它是否是 iPod,请检查它是否可以打电话。
I have added a static method to my project to check the device type: iPad, iPhone4(or less), and iPhone5 to handle the different screen sizes.
You can also use the type UIUserInterfaceIdiomPad.
From what I can tell, the iPod and iPhone are intended to be treated equally. But if you need to determine if it is an iPod, check to see if it makes phone calls.
看看这个 https://github.com/erica/uidevice-extension/
Check this out https://github.com/erica/uidevice-extension/
这篇文章帮助我区分了 iPhone/iPad 类型:
您可以获取型号type (iPhone, iPad, iPod) 如上所示:
为了进一步指定,您可以导入并查找通过以下代码返回为 char 数组的特定模型类型:
并将其转换为 NSString:
This post helped me to distinguish between iPhone/iPad types:
You can get the model type (iPhone, iPad, iPod) as shown above:
And to further specify you can import and find the specific model type returned as char array by the following code:
And convert it to NSString by:
通常的建议是不要担心您运行的设备类型,而是测试您需要的功能。如果您查看设备类型,您一定会做出不正确的假设。例如,在不同市场销售的每种型号的版本可能会有所不同,并且新设备可能会报告相同的类型但具有不同的功能。因此,测试功能而不是模型。
The usual advice is to not worry about what kind of device you're running on, but instead to test for the features you need. If you look at the device type, you're bound to make assumptions that are incorrect. The versions of each model sold in different markets may vary, for example, and new devices may come along that report the same type but have different features. So, test for features rather than model.
您可以定义一些扩展 @csb 对此线程的回答的宏。
You could define some macros extending off of @csb 's answer to this thread.