如何获得iphone设备类型? [英] How can I get iphone device type?

查看:148
本文介绍了如何获得iphone设备类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到iphone设备类型,如果是iphone 2或3G或4在xcode 4.0。



有什么办法得到它吗?



如果是,请告诉我。

解决方案

Caleb 是正确的,你不应该检查设备类型,但功能。例如,您可以检查设备是否支持多任务:

  UIDevice * device = [UIDevice currentDevice]; 
if([device respondingToSelector:@selector(isMultitaskingSupported)]&&& [device isMultitaskingSupported]){
// ...如果支持多任务,则执行代码。
// respondingToSelector:非常有用
}

可以检查iOS版本,但是知道这不是一个替代检查对象 responsesToSelector:

  #define IOS4_0 40000 

//你可能想把这个放在一个方便的方法
NSArray * versions = [[UIDevice currentDevice] .systemVersion componentsSeparatedByString :@。];
NSInteger major = [[versions objectAtIndex:0] intValue];
NSInteger minor = [[versions objectAtIndex:1] intValue];
NSInteger version = major * 10000 + minor * 100;

if(version> = IOS4_0){
// ...为iOS4.0 +
执行的代码}



据我所知,没有记录方法来检查设备模型。


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.

解决方案

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:

UIDevice *device = [UIDevice currentDevice];
if ([device respondsToSelector:@selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {
    // ...code to be executed if multitasking is supported.
    // respondsToSelector: is very useful
}

If you must, you can check the iOS version, but know this is not a substitute for checking whether an object respondsToSelector:.

#define IOS4_0 40000

// You'd probably want to put this in a convenient method
NSArray *versions = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
NSInteger major = [[versions objectAtIndex:0] intValue];
NSInteger minor = [[versions objectAtIndex:1] intValue];
NSInteger version = major * 10000 + minor * 100;

if (version >= IOS4_0) {
    // ...code to be executed for iOS4.0+
}

As far as I know, there is no documented way to check the device model.

这篇关于如何获得iphone设备类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆