uni-app 获取系统信息(九)

uni.getSystemInfo(OBJECT)

获取系统信息。

OBJECT 参数说明:

参数名 类型 必填 说明
success Function 接口调用成功的回调
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

success 返回参数说明:

参数 说明 平台支持
brand 手机品牌 微信小程序
model 手机型号  
pixelRatio 设备像素比  
screenWidth 屏幕宽度  
screenHeight 屏幕高度  
windowWidth 可使用窗口宽度  
windowHeight 可使用窗口高度  
statusBarHeight 状态栏的高度  
language 应用设置的语言  
version 应用版本号  
system 操作系统版本  
platform 客户端平台  
fontSizeSetting 用户字体大小设置。以“我-设置-通用-字体大小”中的设置为准,单位:px 微信小程序
SDKVersion 客户端基础库版本  

示例

uni.getSystemInfo({
    success: function (res) {
        console.log(res.model);
        console.log(res.pixelRatio);
        console.log(res.windowWidth);
        console.log(res.windowHeight);
        console.log(res.language);
        console.log(res.version);
        console.log(res.platform);
    }
});

uni.getSystemInfoSync()

获取系统信息同步接口。

同步返回参数说明

参数 说明
brand 手机品牌
model 手机型号
pixelRatio 设备像素比
screenWidth 屏幕宽度
screenHeight 屏幕高度
windowWidth 可使用窗口宽度
windowHeight 可使用窗口高度
statusBarHeight 状态栏的高度
language 应用设置的语言
version 应用版本号
system 操作系统版本
platform 客户端平台
fontSizeSetting 用户字体大小设置。以“我-设置-通用-字体大小”中的设置为准,单位:px
SDKVersion 客户端基础库版本

示例

try {
    const res = uni.getSystemInfoSync();
    console.log(res.model);
    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) {
    // error
}

uni.canIUse(String)

判断应用的 API,回调,参数,组件等是否在当前版本可用。

String 参数说明

使用 ${API}.${method}.${param}.${options} 或者 ${component}.${attribute}.${option} 方式来调用,例如:

  • ${API} 代表 API 名字
  • ${method} 代表调用方式,有效值为return, success, object, callback
  • ${param} 代表参数或者返回值
  • ${options} 代表参数的可选值
  • ${component} 代表组件名字
  • ${attribute} 代表组件属性
  • ${option} 代表组件属性的可选值

示例

uni.canIUse('getSystemInfoSync.return.screenWidth');
uni.canIUse('getSystemInfo.success.screenWidth');
uni.canIUse('showToast.object.image');
uni.canIUse('request.object.method.GET');

猜你喜欢

转载自blog.csdn.net/zhuoganliwanjin/article/details/81872314
今日推荐