11 手机摇一摇模块 - MiEcosystem/miot-plugin-sdk GitHub Wiki
摇一摇
Export: public
Doc_name: 手机摇一摇模块
Doc_index: 11
Doc_directory: system
Example
import {System} from "miot"
import {ShakeEvent} from "miot"
...
System.shake.startShakeListener().then((res) => {
alert(`startShakeListener: ${ JSON.stringify(res) }`);
})
...
System.shake.stopShakeListener().then((res) => {
alert(`stopShakeListener: ${ JSON.stringify(res) }`);
})
...
-
miot/system
- static
-
inner
-
~IShake
-
.startShakeListener() ⇒
Promise
-
.stopShakeListener() ⇒
Promise
-
.startShakeListener() ⇒
-
~IShake
监听摇一摇事件。需要先调用startShakeListener开始监听,注意及时取消监听
Kind: static constant of miot/system
Since: 10045
Example
ShakeEvent.onShake.addListener(() => {
console.log(`ShakeEvent`);
});
Kind: inner interface of miot/system
-
~IShake
-
.startShakeListener() ⇒
Promise
-
.stopShakeListener() ⇒
Promise
-
.startShakeListener() ⇒
开始监听摇一摇
Kind: instance method of IShake
Returns: Promise
- 成功时:{code:0,message:'success'}
失败时:{code:xxx, message:"xxx" }
Since: 10045
Example
System.shake.startShakeListener().then((res) => {
alert(`startShakeListener: ${ JSON.stringify(res) }`);
}).catch((error) => {
alert(`startShakeListener: ${ JSON.stringify(error) }`);
});
停止监听加速度数据
Kind: instance method of IShake
Returns: Promise
- 成功时:{code:0,message:'success'}
失败时:{code:xxx, message:"xxx" }
Since: 10045
Example
System.shake.stopShakeListener().then((res) => {
alert(`stopShakeListener: ${ JSON.stringify(res) }`);
}).catch((error) => {
alert(`stopShakeListener: ${ JSON.stringify(error) }`);
});