title: Taro.startAccelerometer(res)

sidebar_label: startAccelerometer

Starts listening on acceleration data.

Reference

Type

  1. (res?: Option) => Promise<CallbackResult>

Parameters

Option

Property Type Default Required Description
interval "game" | "ui" | "normal" "normal" No The execution frequency of the acceleration data listening callback function.
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

interval

Property Type Description
game "game" The execution interval of the callback for game updates, which is about 20 ms.
ui "ui" The execution interval of the callback for UI updates, which is about 60 ms.
normal "normal" The normal callback interval, which is about 200 ms.

Sample Code

  1. Taro.startAccelerometer({ interval: 'game' })

API Support

API WeChat Mini-Program H5 React Native
Taro.startAccelerometer ✔️ ✔️ ✔️