Class

UIDevice

A representation of the current device.

Overview

Use a UIDevice object to get information about the device such as assigned name, device model, and operating-system name and version. You also use the UIDevice instance to detect changes in the device’s characteristics, such as physical orientation. You get the current orientation using the orientation property or receive change notifications by registering for the orientationDidChangeNotification notification. Before using either of these techniques to get orientation data, you must enable data delivery using the beginGeneratingDeviceOrientationNotifications() method. When you no longer need to track the device orientation, call the endGeneratingDeviceOrientationNotifications() method to disable the delivery of notifications.

Similarly, you can use the UIDevice instance to obtain information and notifications about changes to the battery’s charge state (described by the batteryState property) and charge level (described by the batteryLevel property). The UIDevice instance also provides access to the proximity sensor state (described by the proximityState property). The proximity sensor detects whether the user is holding the device close to their face. Enable battery monitoring or proximity sensing only when you need it.

You can also use the playInputClick() instance method to play keyboard input clicks in custom input and keyboard accessory views.

Topics

Getting the Shared Device Instance

class var current: UIDevice

Returns an object representing the current device.

Determining the Available Features

var isMultitaskingSupported: Bool

A Boolean value indicating whether multitasking is supported on the current device.

Identifying the Device and Operating System

var name: String

The name identifying the device.

var systemName: String

The name of the operating system running on the device represented by the receiver.

var systemVersion: String

The current version of the operating system.

var model: String

The model of the device.

var localizedModel: String

The model of the device as a localized string.

var userInterfaceIdiom: UIUserInterfaceIdiom

The style of interface to use on the current device.

var identifierForVendor: UUID?

An alphanumeric string that uniquely identifies a device to the app’s vendor.

Tracking the Device Orientation

var orientation: UIDeviceOrientation

Returns the physical orientation of the device.

enum UIDeviceOrientation

The physical orientation of the device.

var isGeneratingDeviceOrientationNotifications: Bool

A Boolean value that indicates whether the receiver generates orientation notifications (true) or not (false).

func beginGeneratingDeviceOrientationNotifications()

Begins the generation of notifications of device orientation changes.

func endGeneratingDeviceOrientationNotifications()

Ends the generation of notifications of device orientation changes.

Determining the Current Orientation

var isPortrait: Bool

Returns a Boolean value indicating whether the device is in a portrait orientation.

var isLandscape: Bool

Returns a Boolean value indicating whether the device is in a landscape orientation.

var isFlat: Bool

A Boolean value indicating whether the specified orientation is face up or face down.

Beta
var isValidInterfaceOrientation: Bool

A Boolean value indicating whether the specified orientation is one of the portrait or landscape orientations.

Getting the Device Battery State

var batteryLevel: Float

The battery charge level for the device.

var isBatteryMonitoringEnabled: Bool

A Boolean value indicating whether battery monitoring is enabled (true) or not (false).

var batteryState: UIDevice.BatteryState

The battery state for the device.

enum UIDevice.BatteryState

The battery power state of the device.

Using the Proximity Sensor

var isProximityMonitoringEnabled: Bool

A Boolean value indicating whether proximity monitoring is enabled (true) or not (false).

var proximityState: Bool

A Boolean value indicating whether the proximity sensor is close to the user (true) or not (false).

Playing Input Clicks

func playInputClick()

Plays an input click in an enabled input view.

Getting the Current Idiom

enum UIUserInterfaceIdiom

The interface type for the device or an object that has a trait environment, such as a view and view controller.

func UI_USER_INTERFACE_IDIOM() -> UIUserInterfaceIdiom

Returns the interface idiom supported by the current device (recommended for apps that run in versions of iOS earlier than 3.2).

Notifications

All UIDevice notifications are posted by the singleton device instance returned by current.

class let orientationDidChangeNotification: NSNotification.Name

Posted when the orientation of the device changes.

class let proximityStateDidChangeNotification: NSNotification.Name

Posted when the state of the proximity sensor changes.

Relationships

Inherits From

Conforms To

See Also

Device Environment

Responding to Changing Display Modes on Apple TV

Change images and resources dynamically when the screen gamut on your device changes.

class UITraitCollection

The iOS interface environment for your app, defined by traits such as horizontal and vertical size class, display scale, and user interface idiom.

protocol UITraitEnvironment

A collection of methods that makes the iOS interface environment available to your app.

protocol UIAdaptivePresentationControllerDelegate

A set of methods that, in conjunction with a presentation controller, determine how to respond to trait changes in your app.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software