Bug 213966 - ios safari doesn't call deviceorientation event
Summary: ios safari doesn't call deviceorientation event
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Website (show other bugs)
Version: Safari 13
Hardware: Unspecified Unspecified
: P2 Blocker
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-04 16:39 PDT by Giorgi
Modified: 2020-07-08 16:38 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giorgi 2020-07-04 16:39:51 PDT
Hi Safari Team...

I am trying to use `deviceorientation` event to be called. The problem is it doesn't get called.


I know that I should request permission to be able to listen to that event.


Here is the code I am using ..

<html>

<button onclick="test()">click here</button>

<script>
    function test(){
        DeviceOrientationEvent.requestPermission()
                .then(response => {
                    if (response == 'granted') {
                        console.log("granted good");
                        window.addEventListener('deviceorientation', (e) => {
                            // do something with e
                            console.log("device orientation changed ", e);
                        })
                    }
                }).catch(err => {
                    console.log("Err ", err);
                })

    }
</script>
</html>


It logs `granted good` , but when I change orientation, it never logs the below log nor the error.

To reproduce the above thing, go to https://glagidze.com/index1.html
Questions:

1) Why doesn't it log when orientation changes ? 
2) Will this work for below IOS versions (even after requesting permission ? )
3) What other solutions (if this doesn't work) should I provide ? (window.orientation looks like it's working, but it's deprecated).


Thanks in advance..
Comment 1 Radar WebKit Bug Importer 2020-07-07 18:50:13 PDT
<rdar://problem/65203472>
Comment 2 Chris Dumez 2020-07-08 08:53:40 PDT
Which build of iOS are you on?
Comment 3 Chris Dumez 2020-07-08 08:56:01 PDT
If I go to https://glagidze.com/index1.html on iOS 14 beta, I see the permission prompt, then plenty of alerts with the orientation (that is different every time). Seems to work as expected for me.
Comment 4 Giorgi 2020-07-08 16:34:22 PDT
My Bad, Chris. I was testing it from Simulator... All good. We can close this issue.
Comment 5 Chris Dumez 2020-07-08 16:38:21 PDT
Good.