系统
获取设备和系统信息,这些信息对于创建响应式布局、优化渲染以及定制用户体验至关重要。本 API 提供同步和异步两种版本,适用不同的使用场景。
TTMinis.game.getSystemInfoSync()
同步获取系统信息。
返回值
字段 | 类型 | 描述 |
|
| 屏幕宽度,单位:px |
|
| 屏幕高度,单位:px |
|
| 可用窗口宽度,单位:px |
|
| 可用窗口高度,单位:px |
|
| 设备像素比 |
|
| 设备像素比 |
|
| 设备屏幕方向 |
|
| 操作系统及版本 |
|
| 客户端平台。有效值: |
|
| 状态栏高度 |
|
| 语言 |
|
| 竖屏方向的安全区域 |
|
| SDK 版本 |
|
| 客户端版本号 |
示例
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)
异步获取系统信息。
参数
字段 | 类型 | 描述 | 是否必填 |
|
| API 调用成功时触发的回调函数 | 否 |
|
| API 调用失败时触发的回调函数 | 否 |
|
| API 调用结束时触发的回调函数(无论成功或失败均会调用) | 否 |
成功回调参数
字段 | 类型 | 描述 |
|
| 屏幕宽度,单位:px |
|
| 屏幕高度,单位:px |
|
| 可用窗口宽度,单位:px |
|
| 可用窗口高度,单位:px |
|
| 设备像素比 |
|
| 设备像素比 |
|
| 设备屏幕方向 |
|
| 操作系统及版本 |
|
| 客户端平台。有效值: |
|
| 状态栏高度 |
|
| 语言 |
|
| 竖屏方向的安全区域 |
|
| SDK 版本 |
|
| 客户端版本号 |
示例
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 起开始支持。低版本需进行兼容性适配。
同步获取窗口信息。
返回值
字段 | 类型 | 描述 |
|
| 设备像素比 |
|
| 屏幕宽度,单位:px |
|
| 屏幕高度,单位:px |
|
| 可用窗口宽度,单位:px |
|
| 可用窗口高度,单位:px |
|
| 状态栏高度,单位:px |
|
| 竖屏方向的安全区域。某些设备没有安全区域概念,因此不会返回 |
|
| 窗口顶部边缘的 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)