79244343

Date: 2024-12-02 14:00:06
Score: 2.5
Natty:
Report link

Facing a similar problem, trying to detect id a iOS 13+ user already gave permission. Came up with this helper:

async requirePermission() {
  if (typeof DeviceMotionEvent?.requestPermission === "function") {
    try {
      const response = await DeviceMotionEvent.requestPermission();
      return response !== "granted";
    } catch (error) {
      return true;
    }
  }
  return false;
}

Here is a complete example and implementation:

https://codepen.io/snap/pen/pvzJxzX

Reasons:
  • Has code block (-0.5):
  • Me too answer (2.5): Facing a similar problem
  • Low reputation (0.5):
Posted by: sn3p