Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xamarin.iOS WKWebView and WKNavigationDelegate custom renderer Intranet SharePoint links not working

sulayjsulayj Member ✭✭

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,

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    You can try to check if the physical device is inside the same segment network with simulator device. The network segment of simulator device should be the same with the Mac ,but we are not sure the physical device will keep the same and have the access of this intranet . So you can try to check that the safari of physical device whether can open a test intranet website first .

  • sulayjsulayj Member ✭✭

    @jezh Thanks for the reply!

    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?

  • jezhjezh Member, Xamarin Team Xamurai

    Then , you can try to keep them in the same segment network, and then try again.

  • sulayjsulayj Member ✭✭

    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.

  • KevinhkKevinhk Member ✭✭

    @sulayj said:
    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.

    any update dude?

Sign In or Register to comment.