| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iPhone OS 2.0 and later. |
| Declared in | UIDevice.h |
| Related sample code |
The UIDevice class provides a singleton instance representing the current device. From this instance you can obtain information about the device such as unique ID, 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 UIDeviceOrientationDidChangeNotification 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.
uniqueIdentifier property
name property
systemName property
systemVersion property
model property
localizedModel property
orientation property
generatesDeviceOrientationNotifications property
– beginGeneratingDeviceOrientationNotifications
– endGeneratingDeviceOrientationNotifications
batteryLevel property
batteryMonitoringEnabled property
batteryState property
proximityMonitoringEnabled property
proximityState property
For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.
The battery charge level for the device.
@property (nonatomic,readonly) float batteryLevel
Battery level ranges from 0.0 (fully discharged) to 1.0 (100% charged). Before accessing this property, ensure that battery monitoring is enabled.
If battery monitoring is not enabled, battery state is UIDeviceBatteryStateUnknown and the value of this property is –1.0.
UIDevice.hA Boolean value indicating whether battery monitoring is enabled (YES) or not (NO).
@property (nonatomic,getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled
Enable battery monitoring only when your application needs to be notified of changes to the battery state. Otherwise, disable battery monitoring. The default value is NO.
UIDevice.hThe battery state for the device.
@property (nonatomic,readonly) UIDeviceBatteryState batteryState
The value for batteryState is one of the constants in “UIDeviceBatteryState.”
If battery monitoring is not enabled, the value of this property is UIDeviceBatteryStateUnknown.
UIDevice.hA Boolean value that indicates whether the receiver generates orientation notifications (YES) or not (NO). (read-only)
@property (nonatomic, readonly, getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications
If the value of this property is YES, the shared UIDevice object posts a UIDeviceOrientationDidChangeNotification notification when the device changes orientation. If the value is NO, it generates no orientation notifications. Device orientation notifications can only be generated between calls to the beginGeneratingDeviceOrientationNotifications and endGeneratingDeviceOrientationNotifications methods.
UIDevice.hThe model of the device as a localized string. (read-only)
@property (nonatomic, readonly, retain) NSString *localizedModel
This string would be a localized version of the string returned from model.
UIDevice.hThe model of the device. (read-only)
@property (nonatomic, readonly, retain) NSString *model
Possible examples of model strings are @”iPhone” and @”iPod touch”.
UIDevice.hThe name identifying the device. (read-only)
@property (nonatomic, readonly, retain) NSString *name
The value of this property is an arbitrary string that is associated with the device as an identifier. For example, you can find the name of an iPhone in the General > About settings.
UIDevice.hReturns the physical orientation of the device. (read-only)
@property (nonatomic, readonly) UIDeviceOrientation orientation
The value of the property is a constant that indicates the current orientation of the device. This value represents the physical orientation of the device and may be different from the current orientation of your application’s user interface. See “UIDeviceOrientation” for descriptions of the possible values.
The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications.
UIDevice.hA Boolean value indicating whether proximity monitoring is enabled (YES) or not (NO).
@property (nonatomic,getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled
Enable proximity monitoring only when your application needs to be notified of changes to the proximity state. Otherwise, disable proximity monitoring. The default value is NO.
Not all iPhone OS devices have proximity sensors. To determine if proximity monitoring is available, attempt to enable it. If the value of the proximityState property remains NO, proximity monitoring is not available.
UIDevice.hA Boolean value indicating whether the proximity sensor is close to the user (YES) or not (NO).
@property (nonatomic,readonly) BOOL proximityState
UIDevice.hThe name of the operating system running on the device represented by the receiver. (read-only)
@property (nonatomic, readonly, retain) NSString *systemName
UIDevice.hThe current version of the operating system. (read-only)
@property (nonatomic, readonly, retain) NSString *systemVersion
An example of the system version is @”1.2”.
UIDevice.hA string unique to each device based on various hardware details. (read-only)
@property (nonatomic, readonly, retain) NSString *uniqueIdentifier
A unique device identifier is a hash value composed from various hardware identifiers such as the device’s serial number. It is guaranteed to be unique for every device but cannot publically be tied to a user account. You can use it, for example, to store high scores for a game in a central server or to control access to registered products. The unique device identifier is sometimes referred to by its abbreviation UDID.
UIDevice.hReturns an object representing the current device.
+ (UIDevice *)currentDevice
A singleton object that represents the current device.
You access the properties of the returned UIDevice instance to obtain information about the device. You must instantiate the UIDevice instance before registering to receive device notifications.
UIDevice.hBegins the generation of notifications of device orientation changes.
- (void)beginGeneratingDeviceOrientationNotifications
You must call this method before attempting to get orientation data from the receiver. This method enables the device’s accelerometer hardware and begins the delivery of acceleration events to the receiver. The receiver subsequently uses these events to post UIDeviceOrientationDidChangeNotification notifications when the device orientation changes and to update the orientation property.
You may nest calls to this method safely, but you should always match each call with a corresponding call to the endGeneratingDeviceOrientationNotifications method.
– endGeneratingDeviceOrientationNotifications @property orientation @property generatesDeviceOrientationNotificationsUIDevice.hEnds the generation of notifications of device orientation changes.
- (void)endGeneratingDeviceOrientationNotifications
This method stops the posting of UIDeviceOrientationDidChangeNotification notifications and notifies the system that it can power down the accelerometer hardware if it is not in use elsewhere. You call this method after a previous call to the beginGeneratingDeviceOrientationNotifications method.
UIDevice.hThe battery power state of the device.
typedef enum {
UIDeviceBatteryStateUnknown,
UIDeviceBatteryStateUnplugged,
UIDeviceBatteryStateCharging,
UIDeviceBatteryStateFull,
} UIDeviceBatteryState;
UIDeviceBatteryStateUnknownThe battery state for the device cannot be determined.
Available in iPhone OS 3.0 and later.
Declared in UIDevice.h.
UIDeviceBatteryStateUnpluggedThe device is not plugged into power; the battery is discharging.
Available in iPhone OS 3.0 and later.
Declared in UIDevice.h.
UIDeviceBatteryStateChargingThe device is plugged into power and the battery is less than 100% charged.
Available in iPhone OS 3.0 and later.
Declared in UIDevice.h.
UIDeviceBatteryStateFullThe device is plugged into power and the battery is 100% charged.
Available in iPhone OS 3.0 and later.
Declared in UIDevice.h.
These constants are used by the batteryState property.
The physical orientation of the device.
typedef enum {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait,
UIDeviceOrientationPortraitUpsideDown,
UIDeviceOrientationLandscapeLeft,
UIDeviceOrientationLandscapeRight,
UIDeviceOrientationFaceUp,
UIDeviceOrientationFaceDown
} UIDeviceOrientation;
UIDeviceOrientationUnknownThe orientation of the device cannot be determined.
Available in iPhone OS 2.0 and later.
Declared in UIDevice.h.
UIDeviceOrientationPortraitThe device is in portrait mode, with the device held upright and the home button at the bottom.
Available in iPhone OS 2.0 and later.
Declared in UIDevice.h.
UIDeviceOrientationPortraitUpsideDownThe device is in portrait mode but upside down, with the device held upright and the home button at the top.
Available in iPhone OS 2.0 and later.
Declared in UIDevice.h.
UIDeviceOrientationLandscapeLeftThe device is in landscape mode, with the device held upright and the home button on the right side.
Available in iPhone OS 2.0 and later.
Declared in UIDevice.h.
UIDeviceOrientationLandscapeRightThe device is in landscape mode, with the device held upright and the home button on the left side.
Available in iPhone OS 2.0 and later.
Declared in UIDevice.h.
UIDeviceOrientationFaceUpThe device is held perpendicular to the ground with the screen facing upwards.
Available in iPhone OS 2.0 and later.
Declared in UIDevice.h.
UIDeviceOrientationFaceDownThe device is held perpendicular to the ground with the screen facing downwards.
Available in iPhone OS 2.0 and later.
Declared in UIDevice.h.
The orientation property uses these constants to identify the device orientation. These constants identify the physical orientation of the device and are not tied to the orientation of your application’s user interface.
All UIDevice notifications are posted by the singleton device instance returned by currentDevice.
Posted when the battery level changes.
Notifications for battery level change are sent no more frequently than once per minute. Do not attempt to calculate battery drainage rate or battery time remaining; drainage rate can change frequently depending on built-in applications as well as your application.
You can obtain the battery level by getting the value of the batteryLevel property.
UIDevice.hPosted when battery state changes.
You can obtain the battery state by getting the value of the batteryState property.
UIDevice.hPosted when the orientation of the device changes.
You can obtain the new orientation by getting the value of the orientation property.
UIDevice.hPosted when the state of the proximity sensor changes.
You can obtain the proximity state by getting the value of the proximityState property.
UIDevice.hLast updated: 2009-04-28