在.NET MAUI Blazor组件应用程序中为MAC Catalyst授予麦克风和摄像头权限。

huangapple go评论64阅读模式
英文:

Grant Permission Of Microphone & Camera In MAC Catalyst In .NET MAUI Blazor Component App

问题

我有一个应用程序,它是用.NET MAUI Blazor Component开发的。

它具有SIP/VOIP功能。

在这个应用程序中,有视频通话的功能。所以当我在Windows上运行这个应用程序时,它可以正常工作,并弹出麦克风和摄像头权限的弹窗。

但是当我尝试在MAC Catalyst上运行同样的应用程序时,麦克风和摄像头权限的弹窗没有显示出来。

我尝试了下面的方法来在MAC Catalyst上显示上述弹窗,但我仍然看不到弹窗。

if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  navigator.mediaDevices.getUserMedia({ audio: true, video: true })
    .then(function(stream) {
    })
    .catch(function(error) {
    });
} else {
}

所以,我的问题是...我如何在MAC Catalyst上显示这个弹窗?如果没有任何方法可以显示这个弹窗,那么我如何以编程方式授予MAC Catalyst的麦克风和摄像头权限。

英文:

I have one application which is developed in .NET MAUI Blazor Component.

It holds a SIP/VOIP functionalities.

In this application, There is functionality of video calling. So when I am running this app on windows, Its working fine and pop-up for permission of mic and camera is showing up.

在.NET MAUI Blazor组件应用程序中为MAC Catalyst授予麦克风和摄像头权限。

But when I am trying to running same application on MAC Catalyst, The pop-up for permission of mic and camera is not showing up there.

I have tried below stuff to show above popup in MAC Catalyst. But I was not able to see popup still.

if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  navigator.mediaDevices.getUserMedia({ audio: true, video: true })
    .then(function(stream) {
    })
    .catch(function(error) {
    });
} else {
}

So, My question is... How can I show this pop-up in MAC Catalyst. If there is not any way to show up this, Then how can I programmatically grant permission of mic & camera in MAC Catalyst.

答案1

得分: 1

是的,我们首先应该添加 NSCameraUsageDescriptionNSMicrophoneUsageDescription

另外,请添加 AVCaptureDevice.RequestAccessForMediaType 来显示提示。考虑以下代码:

// 如果要显示麦克风提示,可以使用 AVAuthorizationMediaType.Audio
AVCaptureDevice.RequestAccessForMediaType (AVAuthorizationMediaType.Video, (bool isPermissionGranted) => 
{                                
    if (isPermissionGranted)
    {
        // 权限已授予
    }
    else
    {
        // 权限未授予
    }
});

然后提示框应该会显示。要了解更多信息,您可以参考 requestAccessForMediaType:completionHandler:

顺便说一下,该提示框将在首次安装应用程序后显示。操作系统将记住用户的响应,因此以后再次使用捕获系统不会再次显示提示框。

希望这对您有所帮助。

在.NET MAUI Blazor组件应用程序中为MAC Catalyst授予麦克风和摄像头权限。

英文:

Yes, we should first add NSCameraUsageDescription and NSMicrophoneUsageDescription.

Also, please add the AVCaptureDevice.RequestAccessForMediaType to show the prompt. Consider the following code:

//if want to show microphone prompt, you could use AVAuthorizationMediaType.Audio
AVCaptureDevice.RequestAccessForMediaType (AVAuthorizationMediaType.Video, (bool isPermissionGranted) => 
{                                
    if(isPermissionGranted)
    {
  
    }
    else
    {
  
    }
});

Then the prompt should show. For more info, you could refer to requestAccessForMediaType:completionHandler:

By the way, the prompt will show at the first time after app is installed. The os will remember the user's response so subsequent uses of the capture system don’t cause the prompt to appear again.

Hope it works.
在.NET MAUI Blazor组件应用程序中为MAC Catalyst授予麦克风和摄像头权限。

huangapple
  • 本文由 发表于 2023年6月5日 22:01:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76407214.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定