码迷,mamicode.com
首页 > 微信 > 详细

微信小程序-设备

时间:2016-11-17 13:41:43      阅读:437      评论:0      收藏:0      [点我收藏+]

标签:mod   direct   sys   rect   success   com   error   mode   catch   

网络状态:

wx.getNetworkType(OBJECT)

获取网络类型。

OBJECT参数说明:

技术分享

wx.getNetworkType({
  success: function(res) {
    var networkType = res.networkType // 返回网络类型2g,3g,4g,wifi
  }
})

系统信息:

wx.getSystemInfo(OBJECT)

获取系统信息。

OBJECT参数说明:

技术分享

success回调参数说明:

技术分享

示例代码:

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)
  }
})

wx.getSystemInfoSync()

获取系统信息同步接口

示例代码:

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)
} catch (e) {
  // Do something when catch error
} 

重力感应:

wx.onAccelerometerChange(CALLBACK)

监听重力感应数据,频率:5次/秒

CALLBACK返回参数:

技术分享

示例代码:

wx.onAccelerometerChange(function(res) {
  console.log(res.x)
  console.log(res.y)
  console.log(res.z)
})

wx.onCompassChange(CALLBACK)

监听罗盘数据,频率:5次/秒

CALLBACK返回参数:

技术分享

示例代码:

wx.onCompassChange(function (res) {
  console.log(res.direction)
})

拨打电话:

wx.makePhoneCall(OBJECT)

OBJECT参数说明:

技术分享

示例代码:

wx.makePhoneCall({
  phoneNumber: 1340000 //仅为示例,并非真实的电话号码
})

 

微信小程序-设备

标签:mod   direct   sys   rect   success   com   error   mode   catch   

原文地址:http://www.cnblogs.com/phpshen/p/6073214.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!