chgatla-microsoft / QRTracking

MRTK sample app for QRtracking
MIT License
74 stars 69 forks source link

RequestAccessAsync does not return if run before permissions are accepted/denied #32

Open camnewnham opened 3 years ago

camnewnham commented 3 years ago

Following on from over here: https://github.com/microsoft/MixedReality-WorldLockingTools-Samples/issues/20

It seems that the first time a project is run that uses QRCodeWatcher.RequestAccessAsync() it will not initialize (await never returns, even after the user has accepted permissions).

This does not occur on subsequent runs as permissions have already been granted.

A workaround is to wait on this function which explicitly will request permission before calling RequestAccessAsync()

        {
#if WINDOWS_UWP
            try
            {
                await new Windows.Media.Capture.MediaCapture().InitializeAsync();
                Debug.Log("Camera and Microphone permissions OK");
                return true;
            }
            catch (UnauthorizedAccessException)
            {
                Debug.LogError("Camera and microphone permissions not granted.");
                return false;
            }
#else
            return true;
#endif
        }