Monday, 2 December 2019

Storing DeviceOrientationEvent and DeviceMotionEvent permissions across pages

I've got a nice DeviceMotionEvent request all working for Safari (or other browsers that require the permission), something along these lines:

// on click of a button
DeviceMotionEvent.requestPermission()
.then(response => {
    if (response == 'granted') {
        // do my thing
    }
})
.catch(function(error) {
    console.log(error);
    // do my other thing
});

And thats working great. But when a user goes to a new page, they have to request the permission again. Obviously I'm calling 'requestPermission' again, so of course they would do.

How do I find out if permission has already been granted? Or is permission granted on a page by page basis (rather than session / site basis)?

I could store the response in localstorage or something, but would prefer something along the lines of:

DeviceMotionEvent.permissionStatus

Or something?



from Storing DeviceOrientationEvent and DeviceMotionEvent permissions across pages

No comments:

Post a Comment