2

I have a web page that I'm loading in Safari on iOS 13.4.1. The web page calls DeviceOrientationEvent.requestPermission() and in the .catch following the .then I'm seeing this error:

NotAllowedError: Requesting device orientation or motion access requires a user gesture to prompt

However there is no pop-up requesting permission.

Does anyone know what I'm missing?

uncle brad
  • 201
  • 1
  • 3
  • 6
  • I think I found the answer here https://stackoverflow.com/questions/56514116/how-do-i-get-deviceorientationevent-and-devicemotionevent-to-work-on-safari?rq=1 I was calling the code from onload. – uncle brad Apr 10 '20 at 17:04
  • D'oh, I did not see your comment/answer here, that's why I added my answer below. For the next time, you might want to provide that as an answer. HTH – superjos Feb 02 '22 at 14:22

1 Answers1

2

Late reply, hoping it might be useful to others.

The call DeviceOrientationEvent.requestPermission() in your code must be performed as a reaction to some user gesture.

So e.g. you would show a dialog to user with a message and a button, explaining what's going to happen next. In button click handler, you hide the dialog and actually call that method.

An example of click handler is given here: https://dev.to/li/how-to-requestpermission-for-devicemotion-and-deviceorientation-events-in-ios-13-46g2 .

superjos
  • 12,189
  • 6
  • 89
  • 134