iOS: Detect if the device is iPhone X family (frameless)

Mark cubn picture Mark cubn · Sep 19, 2018 · Viewed 10.4k times · Source

In my app there is some logic for frameless devices (iPhoneX, Xs Xs max, Xr). Currently it works base on the model of the devices, so, I detect the model by DeviceKit framework.

But I want to extend this logic to future frameless devices. Probably in one year we will have some extra frameless devices. So, how can I detect if device is frameless or not? It should cover all current frameless devices and future one.

We can not rely on faceID, safeAreaInset, screen height or size. So, then what?

Answer

Bence Pattogato picture Bence Pattogato · Sep 19, 2018

You could "fitler" for the top notch, something like:

var hasTopNotch: Bool {
    if #available(iOS 11.0, tvOS 11.0, *) {
        return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
    }
    return false
}