獲取設(shè)備信息這里分為四種,
主要屬性:
網(wǎng)絡(luò)信息wx.getNetWorkType,
系統(tǒng)信息wx.getSystemInfo,
重力感應(yīng)數(shù)據(jù)wx.onAccelerometerChange,
羅盤數(shù)據(jù)wx.onCompassChange
wxml
<button type="primary" bindtap="getNetWorkType">獲取網(wǎng)絡(luò)類型</button><button type="primary" bindtap="getSystemInfo">獲取設(shè)備信息</button><button type="primary" bindtap="onAccelerometerChange">監(jiān)聽重力感應(yīng)數(shù)據(jù)</button><button type="primary" bindtap="onCompassChange">監(jiān)聽羅盤數(shù)據(jù)</button>
js
Page({ data:{ text:"Page system" }, onLoad:function(options){ // 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù) }, /** * 獲取當(dāng)前網(wǎng)絡(luò)狀態(tài) */ getNetWorkType: function() { wx.getNetworkType({ success: function(res) { console.log(res) } }) }, /** * 獲取系統(tǒng)信息 */ getSystemInfo: function() { wx.getSystemInfo({ success: function(res) { console.log(res) } }) }, /** * 監(jiān)聽重力感應(yīng)數(shù)據(jù) * - 帶on開頭的都是監(jiān)聽接收一個(gè)callback */ onAccelerometerChange: function() { wx.onAccelerometerChange(function(res) { console.log(res) }) }, /** * 監(jiān)聽羅盤數(shù)據(jù) */ onCompassChange: function() { wx.onCompassChange(function(res) { console.log(res) }) }, onReady:function(){ // 頁面渲染完成 }, onShow:function(){ // 頁面顯示 }, onHide:function(){ // 頁面隱藏 }, onUnload:function(){ // 頁面關(guān)閉 }})
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注