微信小程序> 微信小程序API设备系统信息

微信小程序API设备系统信息

浏览量:1388 时间: 来源:BlueZhang521

wx.getSystemInfo(OBJECT)

获取系统信息。

OBJECT参数说明:

参数类型必填说明
successFunction接口调用成功的回调
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

success回调参数说明:

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


示例代码:

wx.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)

 }
})

wx.getSystemInfoSync()

获取系统信息同步接口

同步返回参数说明:

参数说明最低版本
model手机型号 
pixelRatio设备像素比 
screenWidth屏幕宽度1.1.0
screenHeight屏幕高度1.1.0
windowWidth可使用窗口宽度 
windowHeight可使用窗口高度 
language微信设置的语言 
version微信版本号 
system操作系统版本 
platform客户端平台 
SDKVersion客户端基础库版本1.1.0

示例代码:

try {
var res = wx.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) {
// Do something when catch error
}

wx.canIUse(String)

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

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

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

例子:

wx.canIUse('openBluetoothAdapter')wx.canIUse('getSystemInfoSync.return.screenWidth')
wx.canIUse('getSystemInfo.success.screenWidth')
wx.canIUse('showToast.object.image')
wx.canIUse('onCompassChange.callback.direction')
wx.canIUse('request.object.method.GET')
wx.canIUse('contact-button')
wx.canIUse('text.selectable')
wx.canIUse('button.open-type.contact')
小程序

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎