源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

微信小程序 获取设备信息 API实例详解

  • 时间:2021-12-05 22:08 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:微信小程序 获取设备信息 API实例详解
[img]http://files.jb51.net/file_images/article/201610/201610295830662.gif?20169295844[/img] 获取设备信息这里分为四种, [b]主要属性:[/b] 网络信息wx.getNetWorkType, [img]http://files.jb51.net/file_images/article/201610/201610295854725.png?20169295915[/img] 系统信息wx.getSystemInfo, [img]http://files.jb51.net/file_images/article/201610/201610295930891.png?20169295942[/img] [b]重力感应数据wx.onAccelerometerChange,[/b] [img]http://files.jb51.net/file_images/article/201610/2016102100002985.png?20169210014[/img] [b]罗盘数据wx.onCompassChange[/b] [img]http://files.jb51.net/file_images/article/201610/2016102100025996.png?20169210040[/img] wxml
<button type="primary" bindtap="getNetWorkType">获取网络类型</button>
<button type="primary" bindtap="getSystemInfo">获取设备信息</button>
<button type="primary" bindtap="onAccelerometerChange">监听重力感应数据</button>
<button type="primary" bindtap="onCompassChange">监听罗盘数据</button>
js
Page({
 data:{
  text:"Page system"
 },
 onLoad:function(options){
  // 页面初始化 options为页面跳转所带来的参数
 },
 /**
  * 获取当前网络状态
  */
 getNetWorkType: function() {
  wx.getNetworkType({
   success: function(res) {
    console.log(res)
   }
  })
 },

 /**
  * 获取系统信息
  */
 getSystemInfo: function() {
  wx.getSystemInfo({
   success: function(res) {
    console.log(res)
   }
  })
 },
 /**
  * 监听重力感应数据   
  *   - 带on开头的都是监听接收一个callback
  */
 onAccelerometerChange: function() {
  wx.onAccelerometerChange(function(res) {
   console.log(res)
  })
 },
  /**
  * 监听罗盘数据
  */
 onCompassChange: function() {
  wx.onCompassChange(function(res) {
   console.log(res)
  })
 },
 onReady:function(){
  // 页面渲染完成
 },
 onShow:function(){
  // 页面显示
 },
 onHide:function(){
  // 页面隐藏
 },
 onUnload:function(){
  // 页面关闭
 }
})



感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部