微信小程序 獲取設備信息 API實例詳解
更新時間:2016年10月02日 10:00:40 作者:順子_RTFSC
這篇文章主要介紹了微信小程序 獲取設備信息 API實例詳解的相關資料,需要的朋友可以參考下
獲取設備信息這里分為四種,
主要屬性:
網絡信息wx.getNetWorkType,
系統信息wx.getSystemInfo,
重力感應數據wx.onAccelerometerChange,
羅盤數據wx.onCompassChange
wxml
<button type="primary" bindtap="getNetWorkType">獲取網絡類型</button> <button type="primary" bindtap="getSystemInfo">獲取設備信息</button> <button type="primary" bindtap="onAccelerometerChange">監(jiān)聽重力感應數據</button> <button type="primary" bindtap="onCompassChange">監(jiān)聽羅盤數據</button>
js
Page({ data:{ text:"Page system" }, onLoad:function(options){ // 頁面初始化 options為頁面跳轉所帶來的參數 }, /** * 獲取當前網絡狀態(tài) */ getNetWorkType: function() { wx.getNetworkType({ success: function(res) { console.log(res) } }) }, /** * 獲取系統信息 */ getSystemInfo: function() { wx.getSystemInfo({ success: function(res) { console.log(res) } }) }, /** * 監(jiān)聽重力感應數據 * - 帶on開頭的都是監(jiān)聽接收一個callback */ onAccelerometerChange: function() { wx.onAccelerometerChange(function(res) { console.log(res) }) }, /** * 監(jiān)聽羅盤數據 */ onCompassChange: function() { wx.onCompassChange(function(res) { console.log(res) }) }, onReady:function(){ // 頁面渲染完成 }, onShow:function(){ // 頁面顯示 }, onHide:function(){ // 頁面隱藏 }, onUnload:function(){ // 頁面關閉 } })
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
您可能感興趣的文章:
相關文章
微信小程序 es6-promise.js封裝請求與處理異步進程
這篇文章主要介紹了微信小程序 es6-promise.js封裝請求與處理異步進程的相關資料,需要的朋友可以參考下2017-06-06