英文:
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.
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
是的,我们首先应该添加 NSCameraUsageDescription
和 NSMicrophoneUsageDescription
。
另外,请添加 AVCaptureDevice.RequestAccessForMediaType 来显示提示。考虑以下代码:
// 如果要显示麦克风提示,可以使用 AVAuthorizationMediaType.Audio
AVCaptureDevice.RequestAccessForMediaType (AVAuthorizationMediaType.Video, (bool isPermissionGranted) =>
{
if (isPermissionGranted)
{
// 权限已授予
}
else
{
// 权限未授予
}
});
然后提示框应该会显示。要了解更多信息,您可以参考 requestAccessForMediaType:completionHandler:。
顺便说一下,该提示框将在首次安装应用程序后显示。操作系统将记住用户的响应,因此以后再次使用捕获系统不会再次显示提示框。
希望这对您有所帮助。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论