The Device
interface provides information about the current device and its environment, as well as methods to control certain device capabilities like wake locks. You can access device-specific metadata such as model, operating system details, orientation, battery state, and localization settings.
Device
is a utility class that exposes static properties and methods. This means you can call its members directly on the class without needing to instantiate it.
For example, you can retrieve the device model like this:
Device.model: string
The device model, e.g., "iPhone"
.
Device.systemVersion: string
The current OS version, such as "16.0"
.
Device.systemName: string
The name of the operating system, typically "iOS"
.
Device.isiPad: boolean
Indicates whether the current device is an iPad.
Device.isiPhone: boolean
Indicates whether the current device is an iPhone.
Device.isiOSAppOnMac: boolean
Checks if the process is an iPhone or iPad app running on a Mac.
Device.batteryState: "full" | "charging" | "unplugged" | "unknown"
The current battery state of the device.
Device.batteryLevel: number
A number between 0.0 and 1.0 representing the battery level.
Device.screen: { width: number; height: number; scale: number }
The current screen's width, height, and scale.
Device.isLandscape: boolean
true
if the device is currently in a landscape orientation.
Device.isPortrait: boolean
true
if the device is currently in a portrait orientation.
Device.isFlat: boolean
true
if the device is lying flat (face up or face down).
Device.colorScheme: "light" | "dark"
The current interface appearance, either "light"
or "dark"
.
Device.systemLocale: string
The current system locale, such as "en_US"
.
Device.systemLocales: string[]
The user’s preferred locales, e.g., ["en-US", "zh-Hans-CN"]
.
Device.systemLanguageTag: string
The current locale language tag, such as "en-US"
.
Device.systemLanguageCode: string
The language code derived from the locale, e.g., "en"
.
Device.systemCountryCode?: string
The country code derived from the locale, e.g., "US"
.
Device.systemScriptCode?: string
The script code if available, e.g., "Hans"
in "zh_CN_Hans"
.
A wake lock prevents the device’s screen from turning off due to inactivity. Use these methods to control the wake lock:
Device.setWakeLockEnabled(enabled: boolean): void
Enable or disable the wake lock. Setting enabled
to true
prevents the screen from sleeping.
Device.isWakeLockEnabled(): Promise<boolean>
Checks if the wake lock is currently enabled.