Search code examples
iosiphoneiphone-x

Future-proof way to detect iPhones with a notch (like the iPhone X)


I have an application that I want to go full screen (hiding the status bar) on iPhones that do not have a notch, but stick to the safe area (keeping the status bar visible) on iPhones that have a notch, like the iPhone X.

I cannot just restrict my application to the safe area on all devices, since the safe area includes the status bar on iPhones that do not have a notch.

The approaches I can think of are:

  • Checking the device model, or
  • Looking at the safe area insets for the main UIWindow and trying to infer something from the actual values (e.g. "if top inset is >22, then it has a notch")

None of the above is very clean, not future-proof.


Solution

  • I was not able to find any "future-proof" way to do this, so I am finally relying on the safe area insets.

    One important note, though, is that this should not be done by checking the top inset alone, as the top inset may vary, for example, when the in-call status bar is being shown. It is better to check either the bottom inset or both bottom and top.