检测IOS设备类型

GMs*_*soF 10 iphone objective-c ipad ios

我从这里找到了解决方案: 使用iPhone SDK确定设备(iPhone,iPod Touch)

从链接中,它建议使用库https://gist.github.com/1323251

但显然这个图书馆已经过时了.我在列表中找不到iPhone 5和新iPad等.

有谁知道如何找到已完成和更新的列表?

非常感谢.

Nit*_*hel 30

您可以轻松检测到iphone,iphone5并且iPad条件如下: -

 if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
 {
     if ([[UIScreen mainScreen] bounds].size.height == 568.0f)
     {


     }
     else
     {
         //iphone 3.5 inch screen
     }
 }
 else
 {
        //[ipad]
 }
Run Code Online (Sandbox Code Playgroud)

我的回答: - 检测设备类型

  • 请不要比较`float`s使用`==`,这是不安全的.你最好使用`[[UIScreen mainScreen] bounds] .size.height> 567`. (8认同)

fah*_*zmi 13

这是https://gist.github.com/1323251的更新版本.我会在新设备发布时保持更新.

https://github.com/froztbytes/UIDeviceHardware


ril*_*lar 11

这很好用:

if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad) {
    NSLog(@"IPAD");
}else{
     NSLog(@"IPHONE");
}
Run Code Online (Sandbox Code Playgroud)

  • 所有得分都应该是最高分的答案! (3认同)

Muk*_*wal 7

刚刚加入@Mohammad Kamran Usmani回答.更具体的iPhone类型:

@import UIKit;

//Check which iPhone it is
double screenHeight = [[UIScreen mainScreen] bounds].size.height;
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
    NSLog(@"All iPads");
} else if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone)
{
    if(screenHeight == 480) {
        NSLog(@"iPhone 4/4S");
        smallFonts = true;
    } else if (screenHeight == 568) {
        NSLog(@"iPhone 5/5S/SE");
        smallFonts = true;
    } else if (screenHeight == 667) {
        NSLog(@"iPhone 6/6S");
    } else if (screenHeight == 736) {
        NSLog(@"iPhone 6+, 6S+");
    } else {
        NSLog(@"Others");
    }
}
Run Code Online (Sandbox Code Playgroud)