Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if the device (iphone) has physical home button?

Tags:

ios

swift

iphone

How to detect in Swift if the current device (iPhone) has a physical home button or hasn't, like: iPhone X, iPhone Xs, iPhone Xs Max, iPhone Xr ?

like image 928
Musa almatri Avatar asked Oct 04 '18 18:10

Musa almatri


People also ask

Do all iPhones have a Home button?

The iPhone SE 2022 is the only current iPhone model with a home button.

How do you check Home button on iPhone?

How To Show The Home Button On Your iPhone's Screen. Go to Settings -> Accessibility -> Touch -> AssistiveTouch and tap the switch next to AssistiveTouch to turn it on. To use the Home button, tap the AssistiveTouch button on the screen, then tap Home.

Does iPhone 11 have a physical Home button?

Apple's introduced the latest of it's line up of iPhones with no Home button. The iPhone 12 series joins the iPhone 11 series, and the iPhone XR, XS and X with a full screen front and Face ID.


2 Answers

For iOS 13 and higher:

    var isBottom: Bool {
    if #available(iOS 13.0, *), UIApplication.shared.windows[0].safeAreaInsets.bottom > 0 {
        return true
    }
    return false
}
like image 185
Vlad Bruno Avatar answered Nov 15 '22 22:11

Vlad Bruno


Check the safe area:

if @available(iOS 11.0, *), 
    UIApplication.sharedApplication.keyWindow?.safeAreaInsets.bottom > 0 {
    return true
}
return false

Swift 4.2 version:-

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

You can also check the device type (check out this post), but checking the safe area is probably the easiest way.

like image 28
Jake Avatar answered Nov 15 '22 23:11

Jake