Swift 5, iOS 13, but compatible with older versions of iOS:
extension UIWindow {
static var isLandscape: Bool {
if #available(iOS 13.0, *) {
return UIApplication.shared.windows
.first?
.windowScene?
.interfaceOrientation
.isLandscape ?? false
} else {
return UIApplication.shared.statusBarOrientation.isLandscape
}
}
}
Usage:
if (UIWindow.isLandscape) {
print("Landscape")
} else {
print("Portrait")
}