Accelerometer event fix for Ios 13+ (#6585)

This commit is contained in:
ChiaNing
2020-04-21 11:32:58 +08:00
committed by GitHub
parent 44844fdb94
commit f20e308025
@@ -72,7 +72,16 @@ export class SystemEvent extends EventTarget {
if (EDITOR) {
return;
}
inputManager.setAccelerometerEnabled(isEnabled);
// for iOS 13+
if (isEnabled && window.DeviceMotionEvent && typeof DeviceMotionEvent.requestPermission === 'function') {
DeviceMotionEvent.requestPermission().then(response => {
console.log(`Device Motion Event request permission: ${response}`);
inputManager.setAccelerometerEnabled(response === 'granted');
});
} else {
inputManager.setAccelerometerEnabled(isEnabled);
}
}
/**