iosxamarin.formsprismwkwebview

Browser also asks camera permission in ios webview


I am having a Xamarin.Forms Prism application. It is using a WKWebView in ios Project to display a web page. In that page, other than the permission from the iOS, a permission popup from browser is also being displayed. Can anybody please help me with this? This is happening only in iOS.


Solution

  • https://learn.microsoft.com/en-us/answers/questions/1167987/how-to-fix-double-permission-popup-in-xamarin-ios

    This thread helped me to solve this problem. Implement a class which is inherited from WKUIDelegate.

      public class CustomWebViewDelegate : WKUIDelegate
        {
            [Export("webView:decideMediaCapturePermissionsForOrigin:initiatedByFrame:type:decisionHandler:")]
            public override void RequestMediaCapturePermission(WKWebView webView, WKSecurityOrigin origin, WKFrameInfo frame, WKMediaCaptureType type, Action<WKPermissionDecision> decisionHandler)
            {
                try
                {
                    decisionHandler(WKPermissionDecision.Grant);
                   base.RequestMediaCapturePermission(webView, origin, frame, type, decisionHandler);
                }
                catch (Exception e)
                { }
            }
        }
    

    Add this statement in the Renderer class.

    webView.UIDelegate = new CustomWebViewDelegate();