检测iOS设备类型

在我的应用程序(用Objective-C编写)中,如何检测设备是iPhone,iPad还是iPhone5?

if([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    // [iphone] or [itouch]
} else {
    // [ipad]
}

解决方法

您可以在以下条件下轻松检测iphone,iphone5和iPad(但不是iTouch!iTouch被视为具有此代码的iPhone!): –

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


     }
     else
     {
         //iphone 3.5 inch screen
     }
 }
 else
 {
        //[ipad]
 }

UPDATE

您也可以使用MACRO或定义变量来检查iPhone5,iPhone4或iPad如Bellow: –

#define isiPhone5  ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
#define isiPhone  (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE

例:-

if(isiPhone)
     {
         if (isiPhone5)
         {


         }
         else
         {
             //iphone 3.5 inch screen
         }
     }
     else
     {
            //[ipad]
     }

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...