locked
Webview navigation url is wrong in IOS RRS feed

  • Question

  • User366562 posted

    I have a sample application in Xamarin.form, which use to showing local HTML content in webview.

    I want to use the navigation event to change the content of webview.

    It working fine in Android but in IOS not getting navigation URL. In IOS navigation getting the full path of IOS application like...

    file://locationpathofIOSapplication/WorkingWithWebviewiOS.app

    Webview implementation code in the attachment.

    Wednesday, June 26, 2019 6:04 AM

Answers

  • User372631 posted

    You can implement it my custom renderer

    in iOS project

    ``` using Foundation; using UIKit; using CoreGraphics;

    using xxx; using xxx.iOS;

    using Xamarin.Forms; using Xamarin.Forms.Platform.iOS;

    [assembly:ExportRenderer(typeof(WebView),typeof(MyWebViewRenderer))] namespace xxx.iOS { public class MyWebViewRenderer:WebViewRenderer,IUIWebViewDelegate { protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e);

            if(NativeView!=null)
            {
    
             //  WeakDelegate = this;
    
            }
    
    
    
        }
    
        [Export("webViewDidFinishLoad:")]
        public void LoadingFinished(UIWebView webView)
        {
    
            var url = webView.Request.Url.AbsoluteString;
    
            MessagingCenter.Send<System.Object, string>(this, "webview_loaded", url); // you can send the url to forms by MessagingCenter
    
        }
    }
    

    }

    ```

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 26, 2019 7:09 AM
  • User366562 posted

    I got answered in StackOverflow. Thanks for the reply.

    https://stackoverflow.com/questions/56766114/webview-navigation-url-is-wrong-in-ios/56768526#56768526

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 26, 2019 10:19 AM

All replies

  • User372631 posted

    You can implement it my custom renderer

    in iOS project

    ``` using Foundation; using UIKit; using CoreGraphics;

    using xxx; using xxx.iOS;

    using Xamarin.Forms; using Xamarin.Forms.Platform.iOS;

    [assembly:ExportRenderer(typeof(WebView),typeof(MyWebViewRenderer))] namespace xxx.iOS { public class MyWebViewRenderer:WebViewRenderer,IUIWebViewDelegate { protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e);

            if(NativeView!=null)
            {
    
             //  WeakDelegate = this;
    
            }
    
    
    
        }
    
        [Export("webViewDidFinishLoad:")]
        public void LoadingFinished(UIWebView webView)
        {
    
            var url = webView.Request.Url.AbsoluteString;
    
            MessagingCenter.Send<System.Object, string>(this, "webview_loaded", url); // you can send the url to forms by MessagingCenter
    
        }
    }
    

    }

    ```

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 26, 2019 7:09 AM
  • User366562 posted

    How can use LoadingFinished ?

    Wednesday, June 26, 2019 9:20 AM
  • User372631 posted

    It will been called auto when webview load finished .

    Wednesday, June 26, 2019 9:36 AM
  • User366562 posted

    I got answered in StackOverflow. Thanks for the reply.

    https://stackoverflow.com/questions/56766114/webview-navigation-url-is-wrong-in-ios/56768526#56768526

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 26, 2019 10:19 AM