Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat program API-device-accelerometer


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.onAccelerometerChange(CALLBACK)


Listen to gravity sensing data, frequency: 5 times per second, the interface calls automatically start listening, wx.stopAccelerometer to stop listening.

CALLBACK returns parameters:

Parameters Type Description
Number X-axis
Y Number Y-axis
Z Number Z-axis

Example code:

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

wx.startAccelerometer(OBJECT)

Base library version 1.1.0 starts to support, and low versions need to be compatible

WeChat Client Version 6.5.6 is supported

Start listening for acceleration data.

OBJECT parameter description:

Parameters Type Required Description
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Example code:

wx.startAccelerometer()

wx.stopAccelerometer(OBJECT)

Base library version 1.1.0 starts to support, and low versions need to be compatible

WeChat Client Version 6.5.6 is supported

Stop listening for acceleration data.

OBJECT parameter description:

Parameters Type Required Description
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Example code:

wx.stopAccelerometer()

wx.offAccelerometerChange(function callback)


Base Library 2.9.3 starts to support, and low versions need to be compatible.

Cancels listening for acceleration data events, with empty parameters, cancels all event listening.

Parameters

function callback

The callback function for acceleration data events