怎么判断程序是否在iPhone5上运行?

问题描述:

应用里有UIViewController 类的接口,我希望应用在iPhone5中运行的时候会知道,怎么样在代码中判断出现在是不是iPhone5?

现在.m文件中:

 #define IS_IPHONE_5 ( [ [ UIScreen mainScreen ] bounds ].size.height == 568 )

然后:

 if( IS_IPHONE_5 )
{
   // 在iphone 5中
}
 else
 {
   // 在其他iphone中
 }

在AppDelegate设置下列代码:

int deviceType;

float height = [UIScreen mainScreen].bounds.size.height;

    if (height==568) {
        self.deviceType = 5;
    }
    else
    {
        self.deviceType = 4;
    }

然后在Xcode中的类中:

if(appdelegate.deviceType == 5){
    iPhone 5 Code...
}
else{
    iPhone 4 code
}