TikTok for Developers

开发者文档

上次更新时间:2026年11月12日

系统

获取设备和系统信息,这些信息对于创建响应式布局、优化渲染以及定制用户体验至关重要。本 API 提供同步和异步两种版本,适用不同的使用场景。

TTMinis.game.getSystemInfoSync()

同步获取系统信息。

返回值

字段

类型

描述

screenWidth

int32

屏幕宽度,单位:px

screenHeight

int32

屏幕高度,单位:px

windowWidth

int32

可用窗口宽度,单位:px

windowHeight

int32

可用窗口高度,单位:px

devicePixelRatio

double

设备像素比

pixelRatio

double

设备像素比

deviceOrientation

string

设备屏幕方向

system

string

操作系统及版本

platform

string

客户端平台。有效值:ios、android。

statusBarHeight

int32

状态栏高度

language

string

语言

safeArea

object

竖屏方向的安全区域

SDKVersion

string

SDK 版本

version

string

客户端版本号

示例

try {
  const res = TTMinis.game.getSystemInfoSync()
  console.log(res.pixelRatio)
  console.log(res.windowWidth)
  console.log(res.windowHeight)
  console.log(res.language)
  console.log(res.version)
  console.log(res.platform)
} catch (e) {
  // Do something when catch error
}

TTMinis.game.getSystemInfo(opts)

异步获取系统信息。

参数

字段

类型

描述

是否必填

success

function

API 调用成功时触发的回调函数

否

fail

function

API 调用失败时触发的回调函数

否

complete

function

API 调用结束时触发的回调函数(无论成功或失败均会调用)

否

成功回调参数

字段

类型

描述

screenWidth

int32

屏幕宽度,单位:px

screenHeight

int32

屏幕高度,单位:px

windowWidth

int32

可用窗口宽度,单位:px

windowHeight

int32

可用窗口高度,单位:px

devicePixelRatio

double

设备像素比

pixelRatio

double

设备像素比

deviceOrientation

string

设备屏幕方向

system

string

操作系统及版本

platform

string

客户端平台。有效值:ios、android。

statusBarHeight

int32

状态栏高度

language

string

语言

safeArea

object

竖屏方向的安全区域

SDKVersion

string

SDK 版本

version

string

客户端版本号

示例

TTMinis.game.getSystemInfo({
  success (res) {
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
    console.log(res.platform)
  }
})

TTMinis.game.getWindowInfo()

注意:从 SDK 版本 0.2.0 起开始支持。低版本需进行兼容性适配。

同步获取窗口信息。

返回值

字段

类型

描述

pixelRatio

double

设备像素比

screenWidth

int32

屏幕宽度,单位:px

screenHeight

int32

屏幕高度,单位:px

windowWidth

int32

可用窗口宽度,单位:px

windowHeight

int32

可用窗口高度,单位:px

statusBarHeight

int32

状态栏高度,单位:px

safeArea

object

竖屏方向的安全区域。某些设备没有安全区域概念,因此不会返回 safeArea 字段。开发者需自行处理这种情况。

screenTop

int32

窗口顶部边缘的 y 坐标

示例

const windowInfo = TTMinis.game.getWindowInfo()

console.log(windowInfo.pixelRatio)
console.log(windowInfo.screenWidth)
console.log(windowInfo.screenHeight)
console.log(windowInfo.windowWidth)
console.log(windowInfo.windowHeight)
console.log(windowInfo.statusBarHeight)
console.log(windowInfo.safeArea)
console.log(windowInfo.screenTop)
TikTok for Developers