如何查看用户使用的iOS设备?

时间:2013-10-26 03:26:32

标签: ios objective-c cocoa-touch

如何找出用户使用的设备?我目前使用的代码是:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if(screenBounds.size.height == 568){
    NSLog(@"User is using an iPhone 5s, 5c, or 5");
}
else{
    NSLog(@"User is using an iPhone 4s or earlier");
}

还有哪些其他数字可以归还,它会是什么设备?例如,我希望这样的事情:

screenBounds.size.height == 568将是iPhone5 / 5s / 5c
screenBounds.size.height == 480将是iPhone 4 / 5s
screenBounds.size.height > 570将成为iPad

等等。我将使用它来根据用户使用的设备更改nib文件,这样我就不必移动每个按钮,图像,标签或任何其他{{1 }}

我没有使用自动布局,因为我还希望根据用户使用的设备进行更多自定义。

1 个答案:

答案 0 :(得分:1)

检查设备类型:

if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
// You are using iPad
    return YES; 
}

else if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomiPhone )
{
  CGRect screenBounds = [[UIScreen mainScreen] bounds];

 if(screenBounds.size.height == 568){
    NSLog(@"User is using an iPhone 5+");

} else{
    NSLog(@"User is using an iPhone 4s-");
}
}