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: