Detect iOS device type

前端 未结 5 2029
感动是毒
感动是毒 2020-11-29 04:16

In my application (written in Objective-C), how do I detect if the device is an iPhone, iPad, or iPhone5?

if([[UIDevice currentDevice]userInterfaceIdiom] ==          


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 04:42

    you can easly detect iphone, iphone5 and iPad with below condition (But not iTouch! iTouch is treated as if it were an iPhone with this code!):-

     if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
     {
         if ([[UIScreen mainScreen] bounds].size.height == 568)
         {
    
    
         }
         else
         {
             //iphone 3.5 inch screen
         }
     }
     else
     {
            //[ipad]
     }
    

    UPDATE

    You can also use MACRO or define Variable for check is that iPhone5,iPhone4 or iPad like Bellow:-

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

    Example:-

    if(isiPhone)
         {
             if (isiPhone5)
             {
    
    
             }
             else
             {
                 //iphone 3.5 inch screen
             }
         }
         else
         {
                //[ipad]
         }
    

提交回复
热议问题