1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-09-12 16:40:40 +08:00
Files
uni-halo/.agents/skills/uni-app/references/feature-system-info.md
T
2026-08-31 07:58:23 +08:00

6.4 KiB

name, description
name description
System Information Device info, system info, and environment detection APIs

System Information

uni.getSystemInfo / getSystemInfoSync

Get device and system information.

// Synchronous (faster, recommended)
const info = uni.getSystemInfoSync()
console.log(info)

// Asynchronous
uni.getSystemInfo({
  success: (res) => {
    console.log(res)
  }
})

// Promise
uni.getSystemInfo().then(res => {
  console.log(res)
})

System Info Properties

Property Type Description
brand String Device brand
model String Device model
pixelRatio Number Device pixel ratio
screenWidth Number Screen width (px)
screenHeight Number Screen height (px)
windowWidth Number Window width (px)
windowHeight Number Window height (px)
statusBarHeight Number Status bar height (px)
language String Language
system String OS version
version String WeChat/Runtime version
platform String Platform: ios/android/windows/mac/devtools
SDKVersion String Client base library version
appId String App ID (DCloud)
appName String App name
appVersion String App version
appCodeName String App code name
uniPlatform String uni-app platform
uniCompileVersion String Compilation version
uniRuntimeVersion String Runtime version
deviceId String Device ID
deviceBrand String Device brand
deviceModel String Device model
deviceType String Device type: phone/pad
osName String OS name
osVersion String OS version
osLanguage String OS language
osTheme String OS theme: light/dark
batteryLevel Number Battery level (0-100)

uni.getAppBaseInfo

Get app base information.

const info = uni.getAppBaseInfo()
// Returns: appId, appName, appVersion, appVersionCode, etc.

uni.getDeviceInfo

Get device hardware information.

const info = uni.getDeviceInfo()
// Returns: brand, model, deviceId, deviceBrand, deviceModel, deviceType

uni.getWindowInfo

Get window information.

const info = uni.getWindowInfo()
// Returns: pixelRatio, screenWidth, screenHeight, windowWidth, windowHeight,
//          statusBarHeight, safeArea, screenTop

Safe Area

Handle notched devices and safe areas.

const info = uni.getSystemInfoSync()

// Safe area info
const safeArea = info.safeArea
console.log(safeArea) // { top, left, right, bottom, width, height }

// Check if device has notch (unsafe area at top)
const hasNotch = info.safeAreaInsets && info.safeAreaInsets.top > 0

Safe Area CSS Variables (App/H5)

.safe-area-bottom {
  padding-bottom: constant(safe-area-inset-bottom); /* iOS 11.0 */
  padding-bottom: env(safe-area-inset-bottom); /* iOS 11.2+ */
}

Network Status

uni.getNetworkType

uni.getNetworkType({
  success: (res) => {
    // res.networkType: wifi/2g/3g/4g/5g/unknown/none
    console.log('Network:', res.networkType)
  }
})

uni.onNetworkStatusChange

// Listen for network changes
uni.onNetworkStatusChange((res) => {
  console.log('Network type:', res.networkType)
  console.log('Is connected:', res.isConnected)
})

// Remove listener
uni.offNetworkStatusChange(callback)

Battery Info

uni.getBatteryInfo

uni.getBatteryInfo({
  success: (res) => {
    console.log('Level:', res.level) // 0-100
    console.log('Is charging:', res.isCharging)
  }
})

Device Orientation

uni.onDeviceMotionChange

uni.startDeviceMotionListening({
  interval: 'normal', // game/ui/normal
  success: () => {
    uni.onDeviceMotionChange((res) => {
      console.log('Alpha:', res.alpha) // 0-360
      console.log('Beta:', res.beta)   // -180 to 180
      console.log('Gamma:', res.gamma) // -90 to 90
    })
  }
})

// Stop listening
uni.stopDeviceMotionListening()

Screen Orientation

// Get current orientation
const info = uni.getSystemInfoSync()
const isLandscape = info.screenWidth > info.screenHeight

// Lock orientation (App only)
plus.screen.lockOrientation('portrait-primary')
// Options: portrait-primary/portrait-secondary/landscape-primary/landscape-secondary

Screen Brightness

// Set brightness (0-1)
uni.setScreenBrightness({
  value: 0.8
})

// Get brightness
uni.getScreenBrightness({
  success: (res) => {
    console.log('Brightness:', res.value)
  }
})

// Keep screen on
uni.setKeepScreenOn({
  keepScreenOn: true
})

Vibration

// Short vibration (15ms)
uni.vibrateShort()

// Long vibration (400ms)
uni.vibrateLong()

// Pattern vibration (App only)
uni.vibrateLong() // or custom pattern

Clipboard

// Set clipboard
uni.setClipboardData({
  data: 'Text to copy',
  success: () => {
    uni.showToast({ title: 'Copied' })
  }
})

// Get clipboard
uni.getClipboardData({
  success: (res) => {
    console.log('Clipboard:', res.data)
  }
})

Phone Call

uni.makePhoneCall({
  phoneNumber: '13800138000'
})

Scan Code

uni.scanCode({
  onlyFromCamera: false, // Allow from album
  scanType: ['qrCode', 'barCode'], // Types to scan
  success: (res) => {
    console.log('Result:', res.result)
    console.log('Type:', res.scanType)
    console.log('CharSet:', res.charSet)
  }
})

Platform Detection

const info = uni.getSystemInfoSync()

// Platform checks
const isIOS = info.platform === 'ios'
const isAndroid = info.platform === 'android'
const isWindows = info.platform === 'windows'
const isMac = info.platform === 'mac'
const isDevtools = info.platform === 'devtools'

// App platform checks
const isApp = info.uniPlatform === 'app'
const isH5 = info.uniPlatform === 'web'
const isWeixinMP = info.uniPlatform === 'mp-weixin'

// Safe area calculation
const safeAreaTop = info.statusBarHeight + (isApp ? 44 : 0) // 44px for nav bar

Storage Info

uni.getStorageInfo({
  success: (res) => {
    console.log('Keys:', res.keys)
    console.log('Current size:', res.currentSize)
    console.log('Limit size:', res.limitSize)
  }
})