Skip to content

11 手机摇一摇模块

Xiaomi-Yule edited this page Jan 20, 2021 · 1 revision

miot/system

摇一摇

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.ShakeEvent

监听摇一摇事件。需要先调用startShakeListener开始监听,注意及时取消监听

Kind: static constant of miot/system
Since: 10045
Example

ShakeEvent.onShake.addListener(() => {
      console.log(`ShakeEvent`);
    });

miot/system~IShake

Kind: inner interface of miot/system


iShake.startShakeListener() ⇒ Promise

开始监听摇一摇

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) }`);
  });

iShake.stopShakeListener() ⇒ Promise

停止监听加速度数据

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) }`);
  });

Clone this wiki locally