加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 检测设备类型

发布时间:2020-12-14 19:49:11 所属栏目:百科 来源:网络整理
导读:在我的应用程序(用Objective-C编写)中,如何检测设备是iPhone,iPad还是iPhone5? if([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { // [iphone] or [itouch]} else { // [ipad]} 解决方法 您可以轻松地检测iphone,iphone5和
在我的应用程序(用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或定义Variable来检查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]
     }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读