1

I am working on one Xamarin forms app and I have created custom renderer to use native web views.

We have some intranet SharePoint URL links in web view content which is not working in iPhone real device. The public URL links are working fine but the intranet SharePoint URL links are not working after click on the link the web view content goes hide automatically and the link is also not opening in Safari browser.

The strange is it is working fine in simulators. The public URL links are also working fine.

The below is our intranet SharePoint URL which is not working in real device and working in simulators.

https://test.demosharepointsite.com/informatik/_layouts/15/WopiFrame.aspx?sourcedoc=%7b25F01E60-0EEC-4A6B-BD26-81B2ED1911CA%7d&file=AA_TenantMigration_2in1_Device_O365.pdf&action=default

Expected behaviour:

When click on the link it should open the URL links in Safari browser.

The following is the code snippet of iOS native custom renderer.


public class ExtendedWebViewRenderer : WkWebViewRenderer
{
    protected override void OnElementChanged(VisualElementChangedEventArgs e)
    {
        try
        {
            base.OnElementChanged(e);
            NavigationDelegate = new AppWKNavigationDelegate(this);
        }
        catch (Exception ex)
        {
            
        }
    }
}

public class AppWKNavigationDelegate : WKNavigationDelegate
{
    ExtendedWebViewRenderer extendedWebViewRenderer;
    public AppWKNavigationDelegate(ExtendedWebViewRenderer _extendedWebViewRenderer)
    {
        
        extendedWebViewRenderer = _extendedWebViewRenderer ?? new ExtendedWebViewRenderer();
    }

    public override async void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
    {
        try
        {
            var extendedWebViewModel = extendedWebViewRenderer.Element as ExtendedWebViewModel;
            if (extendedWebViewModel != null)
            {
                if (webView != null)
                {
                    await System.Threading.Tasks.Task.Delay(100); // wait here till content is rendered
                    if (webView.ScrollView != null)
                    {
                        if (webView.ScrollView.ContentSize != null)
                        {
                            extendedWebViewModel.HeightRequest = (double)webView.ScrollView.ContentSize.Height;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            
        }
    }

    public override void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
    {
        try
        {
            if (navigationAction != null)
            {
                if (navigationAction.NavigationType == WKNavigationType.LinkActivated)
                {
                    if (navigationAction.Request != null)
                    {
                        if (navigationAction.Request.Url != null)
                        {
                            UIApplication.SharedApplication.OpenUrl(navigationAction.Request.Url);
                            decisionHandler(WKNavigationActionPolicy.Cancel);
                        }
                    }
                }
                else
                {
                    decisionHandler(WKNavigationActionPolicy.Allow);
                }
            }
        }
        catch (Exception ex)
        {
            
        }
    }
}


Can anyone help me out here? Thanks.

Sulay Joshi
  • 195
  • 2
  • 9
  • Hi , whehter the physical device inside the same segment network with simulator device ? The network segment of simulator device should be the same with the Mac ,but not sure the pgysical device will keep the same and have the access of this intranet . You can check that the safari of physical device whether can open a test intranet website first . – Junior Jiang Jul 21 '20 at 07:22
  • @JuniorJiang-MSFT No the physical device and simulator both are not in same segment network. Both are in different segment network. But at least the link should be open in Safari browser and the web view content should not be hide autometically. Right? – Sulay Joshi Jul 21 '20 at 10:49
  • If the link could be opened in Safari browser of physical device , then it should work in app . You should keep them in the same segment network at least if in local network environment . – Junior Jiang Jul 22 '20 at 01:36
  • That is not an issue it is fine if the link is not opened in Safari browser and can't reach to server. The main issue is it should not hide the web view content after click on link. – Sulay Joshi Jul 23 '20 at 09:44

0 Answers0