HardwareInformation
open class HardwareInformation
Defines a set of convenience properties and functions when working on Apple devices, such as checking the device model name (iPhone10,3
), getting the device type (iPhoneX
), getting the OS version, the current device orientation and internet connection state.
Examples:
if HardwareInformation.deviceType == .iPhoneX {
// The app is running on an iPhone X
...
}
if HardwareInformation.isConnectedToNetwork {
// The device has an internet connection
...
}
-
Returns
true
if the app is running on an iPhone, else returnsfalse
.Declaration
Swift
public static var isPhone: Bool
-
Returns
true
if the app is running on an iPad, else returnsfalse
.Declaration
Swift
public static var isPad: Bool
-
Returns
true
if the app is runnin on an Apple TV, else returnsfalse
.Declaration
Swift
public static var isTV: Bool
-
Returns
true
if the app is running in Apple CarPlay, else returnsfalse
.Declaration
Swift
public static var isCar: Bool
-
Returns
true
if the app is running on an Apple Watch, else returnsfalse
.Declaration
Swift
public static var isWatch: Bool
-
Returns
true
if the app is running on an Mac, else returnsfalse
.Declaration
Swift
public static var isMac: Bool
-
Returns the model name of the device the app is running on. For example,
iPhone10,3
oriPhone10,6
for theiPhone X
.Declaration
Swift
public static var modelName: String
-
Returns the human readable type of the device that the app is running on (for example
iPhoneX
) orunknown
if the type cannot be discovered.Declaration
Swift
public static var deviceType: AppleHardwareType
-
Returns the version number (for example
iOS 11.1
) of the OS installed on the device that the app is running on.Declaration
Swift
public static var osVersion: String
-
Returns the current orientation of the device that the app is running on. If the orientation is unknown, a guess will be made based on the main screen’s bounds: if the
width
is less than theheight
,portrait
is returned, elselandscapeLeft
is returned.Declaration
Swift
public static var deviceOrientation: UIDeviceOrientation
-
Returns the current orientation of the Apple Watch (based on the crown orientation).
Declaration
Swift
open class HardwareInformation
-
Returns
true
if the device the app is running on has a retina display, else returnsfalse
.Declaration
Swift
public static var isRetinaDisplay: Bool
-
Returns
true
if the device the app is running on has a HD display, else returnsfalse
.Declaration
Swift
public static var isHDDisplay: Bool
-
Returns the bounds of the main screen of the device that the app is running on.
Remark
As of iOS 8.0, these bounds will always be relative to the device’s orientation.Declaration
Swift
public static var screenBounds: CGRect
-
Returns the screen bounds rotated to fit the current device oreintation. If the orientation cannot be discovered, the device is assumed to be in the
portrait
orientation.Remark
This property is deprecated on iOS 8.0 and greater since the main screen bounds are always returned based on the device’s orientation.Declaration
Swift
public static var rotatedScreenBounds: CGRect
-
Returns the Root View Controller for the main window in the app.
Declaration
Swift
public static var rootViewController: UIViewController?
-
Returns
true
if the device the app is running on is connected to the internet, else returnsfalse
.Declaration
Swift
public static var isConnectedToNetwork: Bool
-
Returns
true
if the device the app is running on is connected to the internet via a cellular connection, such as EDGE or GPRS, else returnsfalse
.Declaration
Swift
public static var isWWANNetworkConnection: Bool