Since the iPhone X, Apple has released various sizes of iPhones with a notch.
So, Identifying new iPhones that have a notch or don’t is a new problem for every Apple App Store App Developer. Apple just released in 2020 with iPhone 12, Pro, Pro Max and Mini, which are not similar in screen dimensions to previous generations of iPhone 11.
After reading and surfing the web, I found two helpful articles that will guide you to solve this problem: one post on Stack Overflow and another article by @cafielo.
However, the code shared in both articles above was incompatible with new Apple iOS versions 13 and 14.
So I rewrote those code that may be compatible with Apple iOS 13 and 14 operating system.
Step 01:
First, declare this code as an UIDevice extension in the root of your Swift file, i.e. Public Declaration
extension UIDevice {
var hasNotch: Bool {
let keyWindow = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
if keyWindow?.safeAreaInsets.bottom ?? 0 > 0 {
return true
} else {
return false
}
}
}
Step 02:
Now use this code to get the boolean answer to identify if the iPhone has Notch or not
if UIDevice.current.hasNotch {
print("device with notch")
} else {
print("device without notch")
}
I hope this tutorial helps you to solve your problem.
Thanks & Regards
Mandar Apte