HybridWebView未触发LoadFinished事件

时间:2017-05-19 05:14:05

标签: xamarin.ios xamarin.forms

我正在处理我的第一个Xamarin.IOS应用程序,我想检索webview中加载的HTML页面。为了实现这一目标,我已经引用了Google和Xamarin论坛并实施了以下步骤,但仍未触发LoadFinished事件。任何人都可以帮我解决这个问题。

  1. 使AppDelegate从XFormsApplicationDelegate扩展
  2. 在FinishedLaunching事件中,我有以下一组代码
  3.     
    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
    // Override point for customization after application launch.
    
    // If not required for your application you can safely delete this method
    
    SetIoc();
    Xamarin.Forms.Forms.Init();
    XLabs.Forms.XFormsAppiOS.Init();
    var webHybrid = new XLabs.Forms.Controls.HybridWebViewRenderer();
    
                    return true;
                }
    
                private void SetIoc()
                {
                    var resolverContainer = new SimpleContainer();
    
                    resolverContainer.Register<IDevice>(t => AppleDevice.CurrentDevice)
                                        .Register<IJsonSerializer, SystemJsonSerializer>()
                                        .Register<IDependencyContainer>(t => resolverContainer);
                    Resolver.SetResolver(resolverContainer.GetResolver());
                }
    

    MyViewController具有以下代码

    public partial class MainViewController : UIViewController
    {
    HybridWebView webview;
    
            protected MainViewController(IntPtr handle) : base(handle)
            {
                // Note: this .ctor should not contain any initialization logic.
            }
    
            public override void ViewDidLoad()
            {
                base.ViewDidLoad();
                var webHybrid = new HybridWebViewRenderer();
                webview = new HybridWebView();
            }
    
            void Webview_LoadFinished(object sender, EventArgs e)
            {
                this.webview.RegisterCallback("dataCallback", s =>
                    {
                        System.Diagnostics.Debug.WriteLine(s);
                        this.webview.LoadFinished -= Webview_LoadFinished;
                        this.webview.RemoveCallback("dataCallback");
                    });
    
                this.webview.InjectJavaScript("Native(\"dataCallback\", document.getElementsByTagName('html')[0].innerHTML);");
            }
    
            private void GalleryButtonTouchUpAsync(object sender, EventArgs e)
            {
                webview.Uri = new Uri("http://google.co.in");
                webview.LoadFinished += Webview_LoadFinished;   
            }
        }
    

    你能帮助我找不到的东西吗?

0 个答案:

没有答案