System info

更新时间:
复制 MD 格式

Retrieves device and system information such as model, screen dimensions, OS version, and battery level.

my.getSystemInfo

Note

Supported in mPaaS 10.1.32 and later.

Retrieves device and system information.

Parameters

Name

Type

Required

Description

success

Function

No

Callback on success

fail

Function

No

Callback on failure

complete

Function

No

Callback on completion, regardless of result

Success return values

Name

Type

Description

Minimum Version

model

String

Device model

-

pixelRatio

Number

Device pixel ratio

-

windowWidth

Number

Window width

-

windowHeight

Number

Window height

-

language

String

App language

-

version

String

App version

-

storage

String

Disk capacity

1.1.1

currentBattery

String

Battery percentage

1.1.1

system

String

OS version

1.1.1

platform

String

OS name: Android, iOS, or iPhone OS

1.1.1

titleBarHeight

Number

Title bar height

Supported in mPaaS 10.1.60+.

1.1.1

statusBarHeight

Number

Status bar height

Supported in mPaaS 10.1.60+.

1.1.1

screenWidth

Number

Screen width

1.1.1

screenHeight

Number

Screen height

1.1.1

brand

String

Device brand

1.4.0

fontSizeSetting

Number

User font size

Supported in mPaaS 10.1.60+.

1.4.0

app

String

Client app

-

Model parameter

On iPhone, the model parameter returns the internal device identifier. The following table maps iPhone models to their identifiers:

iPhone model

Model return value

iPhone

iPhone11

iPhone 3G

iPhone12

iPhone 3GS

iPhone21

iPhone 4

iPhone31 / iPhone32 / iPhone33

iPhone 4S

iPhone41

iPhone 5

iPhone51 / iPhone52

iPhone 5S

iPhone61 / iPhone62

iPhone 6

iPhone72

iPhone 6 Plus

iPhone71

iPhone 6S

iPhone8,1

iPhone 6S Plus

iPhone8,2

iPhone 7

iPhone9,1 / iPhone9,3

iPhone 7 Plus

iPhone9,2 / iPhone9,4

iPhone 8

iPhone10,1 / iPhone10,4

iPhone 8 Plus

iPhone10,2 / iPhone10,5

iPhone X

iPhone10,3 / iPhone10,6

iPhone XR

iPhone11,8

iPhone XS

iPhone11,2

iPhone 11

iPhone12,1

iPhone 11 Pro

iPhone12,3

iPhone XS Max

iPhone11,6 / iPhone11,4

iPhone 11 Pro Max

iPhone12,5

Code sample

// API-DEMO page/API/get-system-info/get-system-info.json
{
    "defaultTitle": "Get phone system info"
}
<!-- API-DEMO page/API/get-system-info/get-system-info.axml-->
<view class="page">
  <view class="page-section">
    <view class="page-section-demo">
      <text>Phone model</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.model}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Language</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.language}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Version</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.version}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Window width</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.windowWidth}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Window height</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.windowHeight}}"></input>
    </view>
    <view class="page-section-demo">
      <text>DPI</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.pixelRatio}}"></input>
    </view>
    <view class="page-section-btns">
      <view onTap="getSystemInfo">Get phone system info</view>
      <view onTap="getSystemInfoSync">Get phone system info synchronously</view>
    </view>
  </view>
</view>
// API-DEMO page/API/get-system-info/get-system-info.js
Page({
  data: {
    systemInfo: {}
  },
  getSystemInfo() {
    my.getSystemInfo({
      success: (res) => {
        this.setData({
          systemInfo: res
        })
      }
    })
  },
  getSystemInfoSync() {
    this.setData({
      systemInfo: my.getSystemInfoSync(),
    });
  },
})

my.getSystemInfoSync

Note

Supported in mPaaS 10.1.32 and later.

Synchronous version of getSystemInfo. Returns the same values as the success callback.

Returns undefined on timeout.

Code sample

// API-DEMO page/API/get-system-info/get-system-info.json
{
    "defaultTitle": "Get phone system info"
}
<!-- API-DEMO page/API/get-system-info/get-system-info.axml-->
<view class="page">
  <view class="page-section">
    <view class="page-section-demo">
      <text>Phone model</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.model}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Language</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.language}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Version</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.version}}"></input>
    </view>
    <view class="page-section-demo">
      <text>window width</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.windowWidth}}"></input>
    </view>
    <view class="page-section-demo">
      <text>Window height</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.windowHeight}}"></input>
    </view>
    <view class="page-section-demo">
      <text>DPI</text>
      <input type="text" disabled="{{true}}" value="{{systemInfo.pixelRatio}}"></input>
    </view>
    <view class="page-section-btns">
      <view onTap="getSystemInfo">Get phone system info</view>
      <view onTap="getSystemInfoSync">Get phone system info synchronously</view>
    </view>
  </view>
</view>
// API-DEMO page/API/get-system-info/get-system-info.js
Page({
  data: {
    systemInfo: {}
  },
  getSystemInfo() {
    my.getSystemInfo({
      success: (res) => {
        this.setData({
          systemInfo: res
        })
      }
    })
  },
  getSystemInfoSync() {
    this.setData({
      systemInfo: my.getSystemInfoSync(),
    });
  },
})