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.