Commit 82bcc33b authored by Vũ Gia Vương's avatar Vũ Gia Vương

fix deviceMotionPermission when reload scene

parent 4f8ba74d
import { eventTarget, PLAY_ROLLING_SOUND } from "../Events"; import { eventTarget, PLAY_ROLLING_SOUND } from "../Events";
import { Global } from "../Global";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -14,7 +15,7 @@ export default class DevicemotionController extends cc.Component { ...@@ -14,7 +15,7 @@ export default class DevicemotionController extends cc.Component {
private _isShake = false; private _isShake = false;
protected onLoad(): void { protected onLoad(): void {
if (cc.sys.os === cc.sys.OS_IOS) { if (cc.sys.os === cc.sys.OS_IOS && !Global.deviceMotionPermission) {
this.node.on('click', this.setDeviceMotionIOS, this); this.node.on('click', this.setDeviceMotionIOS, this);
} }
else { else {
...@@ -28,6 +29,7 @@ export default class DevicemotionController extends cc.Component { ...@@ -28,6 +29,7 @@ export default class DevicemotionController extends cc.Component {
(DeviceMotionEvent as any).requestPermission() (DeviceMotionEvent as any).requestPermission()
.then(permissionState => { .then(permissionState => {
if (permissionState === 'granted') { if (permissionState === 'granted') {
Global.deviceMotionPermission = true;
this.setDeviceMotion(); this.setDeviceMotion();
} else { } else {
console.log('Không được cấp quyền sử dụng DeviceMotion'); console.log('Không được cấp quyền sử dụng DeviceMotion');
......
export class Global { export class Global {
public static deviceMotionPermission: boolean = false;
public static getRandomTimeSkew() { public static getRandomTimeSkew() {
return Math.random() * 0.05 + 0.03; return Math.random() * 0.05 + 0.03;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment