On iOS Safari, we must request permission to access device motion data as follows:
if (typeof DeviceMotionEvent.requestPermission === 'function') {
DeviceMotionEvent.requestPermission()
.then(permissionState => {
if (permissionState === 'granted') {
window.addEventListener('devicemotion', () => {});
}
})
.catch(console.error)
;
} else {
// Device is not iOS 13+, no permission requests are neccessary
}
This code must run following a click interaction. Because of this, I am displaying a button, that, when clicked, runs the above code to request permissions.
However, chances are the permission is already granted from when the user previously used my app, and so I would like to avoid showing this button.
How can I check if permission already granted?
from iOS safari - check if permission granted for device motion
No comments:
Post a Comment