May 19, 2021 WeChat Mini Program Development Document
1. wx.onAccelerometerChange(CALLBACK)
2. wx.startAccelerometer(OBJECT)
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)
})
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()
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()
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.
The callback function for acceleration data events