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

前端 未结 9 855
情话喂你
情话喂你 2021-02-05 04:07

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.

9条回答
  •  执笔经年
    2021-02-05 04:47

    Swift 5

    var hasNotch: Bool {
        if #available(iOS 11.0, tvOS 11.0, *) {
            let bottom = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
            return bottom > 0
        } else {
            return false
        }
    }
    

提交回复
热议问题