Xamarin.Forms WebView not working with WebRTC

前端 未结 2 1342
不知归路
不知归路 2021-01-28 18:39

I have worked on WebRTC project, it all works on Web Browser but when I put in in Application WebView, it said not authorized to access device kind a message.

2条回答
  •  孤城傲影
    2021-01-28 19:35

    On Xamarin.Forms, you could use Permissions Plugin. https://github.com/jamesmontemagno/PermissionsPlugin

    Add permission in Manifest file:

    
    

    Create a Utils.cs

    public static class Utils
    {
    public static async Task CheckPermissions(Permission permission)
    {
        var permissionStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(permission);
        bool request = false;
        if (permissionStatus == PermissionStatus.Denied)
        {
            if (Device.RuntimePlatform == Device.iOS)
            {
    
                var title = $"{permission} Permission";
                var question = $"To use this plugin the {permission} permission is required. Please go into Settings and turn on {permission} for the app.";
                var positive = "Settings";
                var negative = "Maybe Later";
                var task = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative);
                if (task == null)
                    return permissionStatus;
    
                var result = await task;
                if (result)
                {
                    CrossPermissions.Current.OpenAppSettings();
                }
    
                return permissionStatus;
            }
    
            request = true;
    
        }
    
        if (request || permissionStatus != PermissionStatus.Granted)
        {
            var newStatus = await CrossPermissions.Current.RequestPermissionsAsync(permission);
    
            if (!newStatus.ContainsKey(permission))
            {
                return permissionStatus;
            }
    
            permissionStatus = newStatus[permission];
    
            if (newStatus[permission] != PermissionStatus.Granted)
            {
                permissionStatus = newStatus[permission];
                var title = $"{permission} Permission";
                var question = $"To use the plugin the {permission} permission is required.";
                var positive = "Settings";
                var negative = "Maybe Later";
                var task = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative);
                if (task == null)
                    return permissionStatus;
    
                var result = await task;
                if (result)
                {
                    CrossPermissions.Current.OpenAppSettings();
                }
                return permissionStatus;
            }
        }
    
        return permissionStatus;
     }
    }
    

    Uasge:

    var status = PermissionStatus.Unknown;
    
        status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
    
        if (status != PermissionStatus.Granted)
        {
    
            status = await Utils.CheckPermissions(Permission.Camera);
        }
    

    Here is a code sample i done before about how to request permission of camera. Xamarin - Requesting camera permissions in WebView

提交回复
热议问题