Skip to content

Instantly share code, notes, and snippets.

@rdlabo
Last active April 5, 2020 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdlabo/b5e5299f69c0e7248eaad9159216ae7b to your computer and use it in GitHub Desktop.
Save rdlabo/b5e5299f69c0e7248eaad9159216ae7b to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { Plugins, MotionEventResult, MotionOrientationEventResult } from '@capacitor/core';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor() {}
async getPermission() {
let permission;
if (
DeviceOrientationEvent &&
typeof DeviceOrientationEvent.requestPermission === 'function'
) {
/**
* Safariの場合
*/
permission = await DeviceOrientationEvent.requestPermission().catch(e => console.log(['Motion Error', e]));
} else {
permission = true;
}
if (permission !== undefined) {
const motionListener = Plugins.Motion.addListener('accel', (accel: MotionEventResult) => {
console.log(['Motion - accel', accel]);
});
const gyroListener = Plugins.Motion.addListener('orientation', (gyro: MotionOrientationEventResult) => {
console.log(['Motion - gyro', gyro]);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment