session-ios/SessionUtilitiesKit/General/UIDevice+featureSupport.swift

87 lines
2.6 KiB
Swift
Raw Normal View History

//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import Foundation
2018-05-25 21:15:19 +02:00
@objc
public extension UIDevice {
2020-11-26 00:37:56 +01:00
var supportsCallKit: Bool {
return ProcessInfo().isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 10, minorVersion: 0, patchVersion: 0))
}
2018-05-25 21:15:19 +02:00
@objc
2020-11-17 06:23:13 +01:00
var hasIPhoneXNotch: Bool {
switch UIScreen.main.nativeBounds.height {
case 960:
// iPad in iPhone compatibility mode (using old iPhone 4 screen size)
return false
case 1136:
// iPhone 5 or 5S or 5C
return false
case 1334:
// iPhone 6/6S/7/8
return false
case 1792:
// iPhone XR
return true
case 1920, 2208:
// iPhone 6+/6S+/7+/8+//
return false
case 2436:
// iPhone X, iPhone XS
return true
case 2688:
// iPhone X Max
return true
default:
// Verify all our IOS_DEVICE_CONSTANT tags make sense when adding a new device size.
return false
}
}
@objc
2020-11-17 06:23:13 +01:00
var isShorterThanIPhone5: Bool {
return UIScreen.main.bounds.height < 568
}
@objc
2020-11-17 06:23:13 +01:00
var isIPad: Bool {
let isNativeIPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad
let isCompatabilityModeIPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone && self.model.hasPrefix("iPad")
return isNativeIPad || isCompatabilityModeIPad
}
2018-10-25 19:02:30 +02:00
@objc
2020-11-17 06:23:13 +01:00
func ows_setOrientation(_ orientation: UIInterfaceOrientation) {
2018-10-25 19:02:30 +02:00
// XXX - This is not officially supported, but there's no other way to programmatically rotate
// the interface.
let orientationKey = "orientation"
self.setValue(orientation.rawValue, forKey: orientationKey)
// Not strictly necessary for the orientation to appear as changed
// but allegedly helps ensure related rotation delegate methods are called.
// https://stackoverflow.com/questions/20987249/how-do-i-programmatically-set-device-orientation-in-ios7
UINavigationController.attemptRotationToDeviceOrientation()
}
2021-08-05 06:57:32 +02:00
var isFullScreen: Bool {
let windowSize = CurrentAppContext().frame.size
let screenSize = UIScreen.main.bounds.size
return windowSize.largerAxis == screenSize.largerAxis && windowSize.smallerAxis == screenSize.smallerAxis
}
}
extension CGSize {
var largerAxis: CGFloat {
Swift.max(width, height)
}
var smallerAxis: CGFloat {
min(width, height)
}
}