import { PluginListenerHandle } from '@capacitor/core';
import { Motion } from '@capacitor/motion';
let accelHandler: PluginListenerHandle;
myButton.addEventListener('click', async () => {
try {
await DeviceMotionEvent.requestPermission();
} catch (e) {
return;
}
accelHandler = await Motion.addListener('accel', event => {
console.log('Device motion event:', event);
});
});
const stopAcceleration = () => {
if (accelHandler) {
accelHandler.remove();
}
};
const removeListeners = () => {
Motion.removeAllListeners();
};