1

Looking at this question Detect if the device is iPhone X, I did the same code as there but I'm getting 560 for height and 320 for the width after running the code in a physical iPhone X in viewDidLoad. I read that UIScreen takes the device's display size. Any idea what could be causing this?

I made this code just to quick check the output.

- (void)viewDidAppear:(BOOL)animated {
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    NSLog([NSString stringWithFormat:@"%f", screenSize.height]);
    NSLog([NSString stringWithFormat:@"%f", screenSize.width]);
    NSLog(@"iPhone X");

}

Output:

560.000000
320.000000 
iPhone X
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Daniel Moreno
  • 128
  • 1
  • 9
  • 5
    You are not using a Launch Screen Storyboard and you haven't added iPhone X launch images. – rmaddy Jul 09 '18 at 18:13
  • BTW - there's no need to detect screen size or device. In most cases, such code is misguided and an indication that the app is being written incorrectly. Not to mention a giant pain every time Apple comes out with a new device with a new screen size. – rmaddy Jul 09 '18 at 18:33
  • @rmaddy Thanks, you're right the app didn't have iPhone x launch images. – Daniel Moreno Jul 09 '18 at 18:39
  • You should be using a single launch screen storyboard instead of all of those separate launch images. – rmaddy Jul 09 '18 at 18:41
  • @rmaddy I know the thing is this app is really old and I have to give maintenance to it, it doesn't even use auto-layout, so yeah it's a pain. – Daniel Moreno Jul 09 '18 at 18:43
  • ...and there are safer ways to see if it's an iPhone X, like check the safe area. – Kerberos Jul 09 '18 at 19:27

1 Answers1

1

You need to setup the Launch Screen File

[xcodeproj] -> [General] -> [App Icons and Launch Images]

enter image description here

Phineas Huang
  • 813
  • 7
  • 19