Heads up! We're sunsetting this forum to streamline our community space.

join us on Discord for support, updates, and all things Snap AR! See you there!
Sign up for our live Camera Kit office hour on July 17 @ 9:30am (PT) / 4:30pm (GMT)

WebSDK taking too long to ask device motion and orientation permissions

aestarita
aestarita Posts: 22 🔥

I am building a world effect where the motion and orientation of the phone are necessary for the effect to work well, the issue I am noticing is that whenever I open the effect in the browser it requests first the camera access (perfect), afterwards it goes through the snap terms and services (great) but then it takes forever to ask for permissions to use motion and orientation. I am talking a whole 30 seconds to 1 minute, and sometimes it never asks for it!

With this in mind is there any way I can force that request of permissions to make sure is happening? 3 pop-ups are a lot for a first-time user but is better than the effect not working perfectly.

Also, I just wanted to flag this to the team to improve the experience for effects that require device position and rotation.

Best Answer

  • Michael Mase
    Michael Mase Posts: 66 🔥🔥
    #2 Answer ✓

    Hi @aestarita! Thanks for your post :) This is a known issue that we are working to correct. You may have success, as you suggested, forcing the prompt on your own:

    function requestDeviceMotionPermission() {
      if (typeof DeviceMotionEvent.requestPermission === 'function') {
        DeviceMotionEvent.requestPermission()
          .then(permissionState => {
            if (permissionState === 'granted') {
              window.addEventListener('devicemotion', (event) => {
                // Handle device motion event
              });
            }
          })
          .catch(console.error);
      } else {
        // Handle regular non iOS 13+ devices
        window.addEventListener('devicemotion', (event) => {
          // Handle device motion event
        });
      }
    }
    
    function requestDeviceOrientationPermission() {
      if (typeof DeviceOrientationEvent.requestPermission === 'function') {
        DeviceOrientationEvent.requestPermission()
          .then(permissionState => {
            if (permissionState === 'granted') {
              window.addEventListener('deviceorientation', (event) => {
                // Handle device orientation event
              });
            }
          })
          .catch(console.error);
      } else {
        // Handle regular non iOS 13+ devices
        window.addEventListener('deviceorientation', (event) => {
          // Handle device orientation event
        });
      }
    }
    
    

Answers

Categories