tt.stopAccelerometer
基础库 1.0.0 开始支持本方法,低版本需做兼容处理。
停止监听加速度数据。
语法
tt.stopAccelerometer(options)
参数
options 为 Object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
success | function | -- | 否 | 接口调用成功的回调函数 | 1.0.0 |
fail | function | -- | 否 | 接口调用失败的回调函数 | 1.0.0 |
complete | function | -- | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 1.0.0 |
回调成功
参数为 Object 类型,属性如下:
参数 | 参数类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | 回调信息 | 1.0.0 |
回调失败
参数为 Object 类型,属性如下:
参数 | 参数类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | 错误信息 | 1.0.0 |
效果示例

扫码体验
请使用字节宿主APP扫码
代码示例
<view>
<button type="default" size="default" bindtap="tapStartAccelerometer">开始加速度计</button>
<button type="default" size="default" bindtap="tapStopAccelerometer">停止加速度计</button>
</view>
Page({
tapStartAccelerometer() {
tt.startAccelerometer({
success(res) {
// 调用开始加速度成功 startAccelerometer:ok
console.log("调用开始加速度成功", res.errMsg);
},
fail(res) {
// 调用开始加速度失败 startAccelerometer:fail
console.log("调用开始加速度失败", res.errMsg);
},
});
},
tapStopAccelerometer() {
tt.stopAccelerometer({
success(res) {
// 调用停止加速度成功 stopAccelerometer:ok
console.log("调用停止加速度成功", res.errMsg);
},
fail(res) {
// 调用停止加速度失败 stopAccelerometer:fail
console.log("调用停止加速度失败", res.errMsg);
},
});
},
});
Bug & Tip
- Tip:调用此接口后,
tt.onAccelerometerChange
中的回调方法将不再执行。
点击纠错
评价此篇文档