One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

Device

Read the current device, OS, and locale snapshot

One.Device returns a snapshot of the device running your app: model, operating system, form factor, simulator state, an app-scoped vendor id, and the effective locale, languages, calendar, time zone, and currency. It reads system APIs directly and never prompts for permission. For the installed app’s own version, build, and bundle ID, use One.AppInfo.

On iOS it reads UIDevice, Locale, and TimeZone. On Android it reads Build, Settings.Secure, and the default locale and time zone. On web the browser reports what it may: the platform string, Intl locale data, and preferred languages, with hardware identity left blank.

Usage

import { One } from 'one'
const info = await One.Device.getInfo()
console.log(info.model, info.systemName, info.systemVersion)
const locale = await One.Device.getLocalizationInfo()
console.log(locale.localeIdentifier, locale.timeZoneIdentifier)

Both calls are snapshots. For locale and calendar values that update with system changes, use Localization and its React hooks.

How it works

getInfo builds one object per call. On iOS the model is Apple’s device family string such as iPhone, not a retail model name, and the vendor identifier is identifierForVendor, which can be absent until after the user first unlocks the device and can change once all of a vendor’s apps are removed. On Android the model is Build.MODEL, the system name is Android, the version is the release string, and the vendor identifier is ANDROID_ID, scoped to the app signing key and never a hardware id. The interface idiom is phone, pad, tv, carPlay, mac, vision, or unspecified; Android reports tv for television, pad for smallest width 600dp and up, and phone otherwise. isSimulator tells the iOS simulator or an Android emulator apart from hardware.

getLocalizationInfo reads the effective locale as a BCP 47 tag, the preferred language tags, the calendar identifier, the time zone identifier, the current UTC offset in seconds (positive east of UTC, reflecting daylight saving time at the moment of the call), and the currency code when the platform exposes one. On web the locale, calendar, and time zone come from Intl.DateTimeFormat, languages from navigator.languages, and currency stays absent since browsers do not expose the user’s chosen currency. Server rendering returns empty strings, empty language lists, a zero offset, and no currency.

API reference

MethodsTypeDescription
getInfo() => Promise<DeviceInfo>Model, OS, idiom, simulator flag, and vendor id.
() => Promise<DeviceInfo>Model, OS, idiom, simulator flag, and vendor id.
getLocalizationInfo() => Promise<LocalizationInfo>Locale, languages, calendar, time zone, and currency.
() => Promise<LocalizationInfo>Locale, languages, calendar, time zone, and currency.
Device infoTypeDescription
modelstringDevice family on iOS, Build model on Android.
stringDevice family on iOS, Build model on Android.
systemNamestringThe OS name.
stringThe OS name.
systemVersionstringThe OS version string.
stringThe OS version string.
interfaceIdiomstringPhone, pad, tv, carPlay, mac, vision, or unspecified.
stringPhone, pad, tv, carPlay, mac, vision, or unspecified.
isSimulatorbooleanSimulator or emulator rather than hardware.
booleanSimulator or emulator rather than hardware.
vendorIdentifierstringApp-scoped vendor id, when available.
stringApp-scoped vendor id, when available.
Localization infoTypeDescription
localeIdentifierstringEffective locale as a BCP 47 tag.
stringEffective locale as a BCP 47 tag.
preferredLanguagesstring[]Preferred language tags, best first.
string[]Preferred language tags, best first.
calendarIdentifierstringThe calendar identifier.
stringThe calendar identifier.
timeZoneIdentifierstringThe time zone identifier.
stringThe time zone identifier.
timeZoneOffsetSecondsnumberCurrent UTC offset, positive east.
numberCurrent UTC offset, positive east.
currencyCodestringThe currency code, when exposed.
stringThe currency code, when exposed.

Platform differences

iOSAndroidWeb
ModelDevice familyBuild modelEmpty
Vendor idVendor scopedApp key scopedAbsent
IdiomSystem idiomSize basedUnspecified
CurrencyWhen exposedWhen exposedAbsent

Limits and gotchas

Examples

Adapt to tablets

import { useEffect, useState } from 'react'
import { One } from 'one'
function useIsPad() {
const [isPad, setIsPad] = useState(false)
useEffect(() => {
One.Device.getInfo().then((info) => {
setIsPad(info.interfaceIdiom === 'pad')
})
}, [])
return isPad
}

The idiom read happens once on mount, since the form factor cannot change under a running app. Phones and tablets then branch on one boolean.

Format with the device time zone

import { useEffect, useState } from 'react'
import { Text } from 'react-native'
import { One } from 'one'
function LocalTime({ whenMs }: { whenMs: number }) {
const [label, setLabel] = useState('')
useEffect(() => {
One.Device.getLocalizationInfo().then((locale) => {
setLabel(
new Intl.DateTimeFormat(locale.localeIdentifier, {
timeZone: locale.timeZoneIdentifier,
hour: 'numeric',
minute: '2-digit',
}).format(new Date(whenMs))
)
})
}, [whenMs])
return <Text>{label}</Text>
}

Formatting with the reported locale and zone keeps times consistent with the rest of the device, including daylight saving time at the moment of the call.

Edit this page on GitHub.