0

I found a code in another article.

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


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

This article is the article code of 5 years ago. I think that it is too old. Because it is not compatible with iPhone 10.

Please tell me the latest code that allows for flexibility.

WaFuNuke
  • 37
  • 1
  • 10
  • 4
    Possible duplicate of [Detect if the device is iPhone X](https://stackoverflow.com/questions/46192280/detect-if-the-device-is-iphone-x) – trungduc Jul 02 '18 at 07:27
  • @trungduc Thanks for comments. ad i found code 'if UIDevice().userInterfaceIdiom =...'. I think this code is good for me. :) – WaFuNuke Jul 02 '18 at 07:31
  • @trungduc Thanks i did it !! This problem solved. please write as answer. then i check mark. – WaFuNuke Jul 02 '18 at 07:36
  • 1
    Actually it's not my answer so I think you should upvote the answer in above link instead. Don't forget to go around Google before creating a new question at the next time :) – trungduc Jul 02 '18 at 07:42
  • @trungduc Okie :) – WaFuNuke Jul 02 '18 at 07:43

1 Answers1

0

This is what I use in my apps; it works a treat:

if UIDevice().userInterfaceIdiom == .phone && UIScreen.main.nativeBounds.height == 2436 {
   // Device is iPhone X 
}else if UIDevice().userInterfaceIdiom == .pad && UIScreen.main.nativeBounds.height == 1668 {
   // Device is iPad Pro 10.5' X 
}else{ 
   //Device is something else 
}

If you go to the Apple Developer Documentation Archive, you can pick out the properties you'd like to use to detect a specific device. Perhaps a switch statement would be more appropriate if there will be multiple cases.

Steve
  • 4,372
  • 26
  • 37