URL not opening iOS webview custom renderer Xamarin forms

Bhuwan 801 Reputation points
2023-02-26T04:54:12.9766667+00:00

Hi

I am facing an issue on the WebView URL renderer on iOS after the render page displays blank and the same page will be visible on Android devices. On Url getting some console error like some images not working.

Below function is deprecated on iOS version or change method means if page not working or not renderer then how to display message in place of blank page.

webViewWebContentProcessDidTerminate

below the iOS custom view renderer.

[assembly: ExportRenderer(typeof(CustomWebView), typeof(CustomWebViewRenderer))]
namespace Yuro.iOS.Controls
{
    /// <summary>
    /// CustomWebViewRenderer
    /// </summary>
    public class CustomWebViewRenderer : ViewRenderer<CustomWebView, WKWebView>
    {
        /// <summary>
        /// _wkWebView
        /// </summary>
        WKWebView _wkWebView;

        /// <summary>
        /// OnElementChanged
        /// </summary>
        /// <param name="e"></param>
        protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
        {
            try
            {
                base.OnElementChanged(e);

                if (Control == null)
                {
                    var config = new WKWebViewConfiguration();
                    config.AllowsInlineMediaPlayback = true;
                    config.MediaPlaybackRequiresUserAction = false;
                    _wkWebView = new WKWebView(Frame, config);
                    SetNativeControl(_wkWebView);
                }
                if (e.NewElement != null)
                {
                    Control.LoadRequest(new NSUrlRequest(new NSUrl(Element.Url)));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,377 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,161 Reputation points Microsoft External Staff
    2023-02-28T05:44:11.6666667+00:00

    Hello,

    This issue is caused by the server side. The picture links are not responding. You can refer to the above link to enable Web Inspector and debug this webview via Safari, then adjust the content on server side.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.