iOS get permisson for motion sensors
Posted: Mon Dec 16, 2019 3:00 pm
Since iOS 13 it is necessary, to get the permissions from user to be authorized to interrogate the motion sensors.
Otherwise things like VR view and Babylon will not work anymore..
I found an working javascript example @ https://github.com/aframevr/aframe/issues/4287
But how can I integrate this as a function in spiderbasic?
Any help is welcome!
Otherwise things like VR view and Babylon will not work anymore..
I found an working javascript example @ https://github.com/aframevr/aframe/issues/4287
But how can I integrate this as a function in spiderbasic?
Code: Select all
window.onload = function () {
// Check if is IOS 13 when page loads.
if ( window.DeviceMotionEvent && typeof window.DeviceMotionEvent.requestPermission === 'function' ){
// Everything here is just a lazy banner. You can do the banner your way.
const banner = document.createElement('div')
banner.innerHTML = `<div style="z-index: 1; position: absolute; width: 100%; background-color:#000; color: #fff"><p style="padding: 10px">Click here to enable DeviceMotion</p></div>`
banner.onclick = ClickRequestDeviceMotionEvent // You NEED to bind the function into a onClick event. An artificial 'onClick' will NOT work.
document.querySelector('body').appendChild(banner)
}
}
function ClickRequestDeviceMotionEvent () {
window.DeviceMotionEvent.requestPermission()
.then(response => {
if (response === 'granted') {
window.addEventListener('devicemotion',
() => { console.log('DeviceMotion permissions granted.') },
(e) => { throw e }
)} else {
console.log('DeviceMotion permissions not granted.')
}
})
.catch(e => {
console.error(e)
})
}