I am trying to get access to the iPhones Accelerometer. Since iOS 13 You have to ask for Permission in App. I am using IOS 14 and I don't even get an request. It gets denied right away
if(typeof(DeviceMotionEvent) !== 'undifined' && typeof(DeviceOrientationEvent.requestPermission) === "function"){
// requestAcces()
}
function requestAcces(){
DeviceOrientationEvent.requestPermission()
.then(permissionState => {
text(permissionState,100, 100); // answer is "denied"
if (permissionState === 'granted') {
window.addEventListener('deviceorientation', () => {});
}
})
.catch(console.error);
}
The
requestAccess()function needs to be triggered by the user's action, for example, as a callback function for buttononclickevent. Here is a demo: https://accelerometerdemo.netlify.app