Today there exists an event deviceorientationabsolute that can be used to register to device orientation events that are relative to the magnetic north pole (for 1D compass heading calculations)
This event is available on other browsers except Safari.
On Safari window.addEventListener('deviceorientationabsolute', ...) does not work, but instead one must first call DeviceOrientationEvent.requestPermission() and after that Promise resolves to a success, register to the window.addEventListener('deviceorientation', ...) event, and use DeviceOrientationEvent.webkitCompassHeading to acquire the 1D compass heading direction.
In other browsers today, I understand that one does not need to call DeviceOrientationEvent.requestPermission() before registering a deviceorientationabsolute event handler, though I presume that since the function is in the spec, that in the future this may also be required.
But this gives a problem: what kind of code should one write in order to precisely register to get 1D compass heading directions in a manner that will be forward-compatible to future Firefox, Chrome and Safari browsers?
We can feature test whether DeviceOrientationEvent.requestPermission() exists and call it before registering a handler, but how does one know precisely whether to register 'deviceorientation' or 'deviceorientationabsolute' events?
Today there exists an event deviceorientationabsolute that can be used to register to device orientation events that are relative to the magnetic north pole (for 1D compass heading calculations)
This event is available on other browsers except Safari.
On Safari
window.addEventListener('deviceorientationabsolute', ...)does not work, but instead one must first callDeviceOrientationEvent.requestPermission()and after that Promise resolves to a success, register to thewindow.addEventListener('deviceorientation', ...)event, and useDeviceOrientationEvent.webkitCompassHeadingto acquire the 1D compass heading direction.In other browsers today, I understand that one does not need to call
DeviceOrientationEvent.requestPermission()before registering adeviceorientationabsoluteevent handler, though I presume that since the function is in the spec, that in the future this may also be required.But this gives a problem: what kind of code should one write in order to precisely register to get 1D compass heading directions in a manner that will be forward-compatible to future Firefox, Chrome and Safari browsers?
We can feature test whether
DeviceOrientationEvent.requestPermission()exists and call it before registering a handler, but how does one know precisely whether to register'deviceorientation'or'deviceorientationabsolute'events?