docs/api/accelerometer.md
监听加速度数据
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | 4.41 | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> |
App平台请搜索插件市场
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| callback | (result: OnAccelerometerChangeCallbackResult) => void | 是 | - | Web: x; 微信小程序: -; Android: x; iOS: x; HarmonyOS: x |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| x | number | 是 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | X 轴 |
| y | number | 是 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | Y 轴 |
| z | number | 是 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | Z 轴 |
取消监听加速度数据
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | 4.41 | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| callback | (result: any) => void | 是 | - | Web: x; 微信小程序: -; Android: x; iOS: x; HarmonyOS: x |
开始监听加速度数据
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | 4.41 | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | StartAccelerometerOptions | 是 | - | Web: x; 微信小程序: -; Android: x; iOS: x; HarmonyOS: x |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| interval | string | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 回调频率 |
| success | (result: StartAccelerometerSuccess) => void | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 成功返回的回调函数 |
| fail | (result: UniError) => void | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 失败的回调函数 |
| complete | (result: any) => void | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 结束的回调函数(调用成功、失败都会执行) |
| 合法值 | 兼容性 | 描述 |
|---|---|---|
| game | Web: x; 微信小程序: -; Android: x; iOS: x; HarmonyOS: x | 适用于更新游戏的回调频率,在 20ms/次 左右 |
| ui | Web: x; 微信小程序: -; Android: x; iOS: x; HarmonyOS: x | 适用于更新游戏的回调频率,在 20ms/次 左右 |
| normal | Web: x; 微信小程序: -; Android: x; iOS: x; HarmonyOS: x | 普通的回调频率,在 200ms/次 左右 |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| errMsg | string | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 错误信息 |
停止监听加速度数据
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | 4.41 | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | StopAccelerometerOptions | 是 | - | Web: x; 微信小程序: -; Android: x; iOS: x; HarmonyOS: x |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| success | (result: StopAccelerometerSuccess) => void | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 成功返回的回调函数 |
| fail | (result: UniError) => void | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 失败的回调函数 |
| complete | (result: any) => void | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 结束的回调函数(调用成功、失败都会执行) |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| errMsg | string | 否 | - | Web: x; 微信小程序: 4.41; Android: x; iOS: x; HarmonyOS: x | 错误信息 |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| errMsg | string | 是 | - | Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: - | 错误信息 |