Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios 13 DeviceOrientationEvent.requestPermission: how to force device to ask again for user permission

In iOS 13 Apple has introduced the API DeviceOrientationEvent.requestPermission. It must be triggered on user action (click, tap or equivalent). My problem here is that the result seems to be cached, so in case the user denies permission I can't ask access again (the promise is automatically fulfilled with the cached value). Is there any way to force the device to forgot the cached value and ask again for the user permission to access orientation data (I mean it should display again the popup window where the user can allow or deny access)?

This is the relevant code:

if (DeviceOrientationEvent && typeof(DeviceOrientationEvent.requestPermission) === "function") {
    const permissionState = await DeviceOrientationEvent.requestPermission();

    if (permissionState === "granted") {
        // Permission granted    
    } else {
        // Permission denied
    }
}
like image 885
revy Avatar asked Sep 24 '19 16:09

revy


2 Answers

I see the same behavior on iOS 13 Safari. You need to remove the website data for the particular site that needs permission. Go to Settings > Safari > Advanced > Website data, lookup the site and remove all the data. Then the prompt should show up again when you ask for permission.

like image 115
Danny Moerkerke Avatar answered Sep 26 '22 16:09

Danny Moerkerke


Try simply to quit Safari and launch it back. The prompt will come back.

like image 36
lsmpascal Avatar answered Sep 24 '22 16:09

lsmpascal