Last active
April 5, 2020 03:22
-
-
Save rdlabo/b5e5299f69c0e7248eaad9159216ae7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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