-1

I am trying to detect an iPhoneX in objective C and have found several posts/guides/websites, such as https://hype.codes/how-detect-iphone-x-programmatically that show how to do it and the values to compare it against. This usually means checking the [[UIScreen mainScreen] nativeBounds].size.height for 2436 or [[UIScreen mainScreen] bounds].size.height for 812

But here's the weird part: When I use either height sizes, I get different results than the expected values.

For the nativebounds, I get 2001, not 2436 when using the bounds, I get 667, not 812, which is the same as any iphone6/7/8 detection

In both cases I conclude to be missing the 145px (and nativebounds @3x=435) size difference, but why can't I get the correct size? like it shows in the iOS human interface guidelines ios human interface guidelines dimensions

I have tried this on both the simulator and an actual iphoneX, someone was so kind to let me experiment with, but keep running into this, I am completely stuck with this.

I am really hoping someone can help me on identifying and solving this issue, maaany thanks in advance.

Eelco
  • 1
  • 1

1 Answers1

2

I couldn't reproduce your issue personally, but then I found the answer here: https://stackoverflow.com/a/47819966/341994

In brief, you are building against an earlier iOS system or version of Xcode (or both), where the iPhone X is unknown. So, just as you say, the iPhone X behaves as an iPhone 8, because that is something your iOS system understands. If it didn't do that, all older apps would break on the iPhone X. And the values given are accurate, because the dimensions you are being given are the dimensions at which the app is displayed; it is "letterboxed" into those dimensions.

Update to Xcode 9.2 and build against iOS 11.2 to solve your problem.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Good find, I did not find that post. Yeah, so short after I wrote my post, I figured to create a new project instead to see what that does, it gives the correct values. However, I have checked all the deployment targets I could find and change them to 11.2 for my existing project, it still gives me the wrong ones. – Eelco Mar 21 '18 at 17:41
  • @Eelco You could figure this out by fiddling with the build settings, but why bother? The new project works, so migrate everything into the new project and you're all set. – matt Mar 21 '18 at 17:54
  • The thing is that it's a years long project, it wouldn't surprise me if somewhere I am missing a setting or perhaps from some imported pod if thats possible, but what exactly do you mean with migrating into a new project? copy the files? – Eelco Mar 22 '18 at 15:28
  • Okay so you refuse to migrate. Let’s try something else. If this project is old, perhaps it lacks a launch storyboard. It needs one. I would have expected you’d have noticed that problem by now, but perhaps not ... ? – matt Mar 22 '18 at 15:44