Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhoneX and Notch detection

Using Javascript; how can I check if the users device is an iPhoneX?

Also, how can I determine what side the iPhones' 'notch' is positioned when in the landscape orientation?

There are some great articles out there: https://webkit.org/blog/7929/designing-websites-for-iphone-x/

... but these tend to take advantage of cutting-edge features that aren't natively supported in many mobile browsers at the time of writing this.

like image 764
Mark Notton Avatar asked Nov 10 '17 16:11

Mark Notton


People also ask

What is the purpose of the iPhone notch?

There are valid reasons why the iPhone has a notch: the cut out area conceals the components for Face ID, which is Apple's facial recognition system that keeps your iPhone secure (although your iPhone is only ever as secure as your pin). Face ID also means you don't have to enter your password all the time.

Does Apple call it a notch?

The notch, which Apple calls the TrueDepth camera array, was a controversial design decision introduced in 2017 on the ‌iPhone‌ X, and it has remained largely unchanged on subsequent ‌iPhone‌ models until the ‌iPhone 13‌ and iPhone 13 Pro, which slightly reduced it in size.


1 Answers

iPhone X and 11 have 9:19.5 aspect ratio:

9 / 19.5 = 0.4615384615.toFixed(3) = "0.462"

Let's try this on all iPhone X and 11 using window.screen.

X, Xs, Xs Max (Display Zoom: Zoomed), 11 Pro, 11 Pro Max (Display Zoom: Zoomed):

375 / 812 = 0.4618226601.toFixed(3) = "0.462"

Xs Max (Display Zoom: Standard), XR, 11, 11 Pro Max (Display Zoom: Standard):

414 / 896 = 0.4620535714.toFixed(3) = "0.462"

So...

let iPhone = /iPhone/.test(navigator.userAgent) && !window.MSStream
let aspect = window.screen.width / window.screen.height
if (iPhone && aspect.toFixed(3) === "0.462") {
    // I'm an iPhone X or 11...
}

Please keep in mind, window.screen always return sizes in portrait, regardless active device orientation.

like image 175
StelArian Avatar answered Sep 20 '22 19:09

StelArian