public override bool ShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType) { string result = WebUtility.UrlDecode(request.ToString()); if (result.StartsWith("myapp://")) { Debug.WriteLine("JavaScript function calling C# function. The result is => " + result); return(false); } return(true); }
public override bool ShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType) { Debug.WriteLine("ShouldStartLoad"); string text = request.ToString(); if (text.Contains("http://")) { if (UIApplication.SharedApplication.CanOpenUrl(request.Url)) { UIApplication.SharedApplication.OpenUrl(request.Url); } return(false); } //Console.WriteLine("[Custom Delegate] Url: {0}", request.Url); //Console.WriteLine("[Custom Delegate] MainDocUrl: {0}", request.MainDocumentURL); if (text.Contains("COMPLETE")) { Console.WriteLine("COMPLETE!"); return(false); } else if (text.Contains("EXPAND")) { ExpandParadigm(); return(false); } else if (text.Contains("PRINT")) { Console.WriteLine(text); return(false); } else if (text.Contains("ANNOTATION")) { text = WebUtility.UrlDecode(text); string english = text.Split('|')[3]; string chinese = text.Split('|')[1]; string pinyin = text.Split('|')[2]; Console.WriteLine("english => " + english); Console.WriteLine("chinese => " + chinese); Console.WriteLine("pinyin => " + pinyin); Word word = new Word() { Chinese = chinese, Pinyin = pinyin, English = english }; DisplayDialogParadigm(webView, word); return(false); } else if (text.Contains("GET_WORD")) { string word = text.Split(new[] { "word=" }, StringSplitOptions.RemoveEmptyEntries).Last(); string anno = Annotate(word); return(false); } WebNavigationEvent navEvent = WebNavigationEvent.NewPage; switch (navigationType) { case UIWebViewNavigationType.LinkClicked: navEvent = WebNavigationEvent.NewPage; break; case UIWebViewNavigationType.FormSubmitted: navEvent = WebNavigationEvent.NewPage; break; case UIWebViewNavigationType.Reload: navEvent = WebNavigationEvent.Refresh; break; case UIWebViewNavigationType.FormResubmitted: navEvent = WebNavigationEvent.NewPage; break; case UIWebViewNavigationType.Other: navEvent = WebNavigationEvent.NewPage; break; } lastEvent = navEvent; return(true); }
public override void DecidePolicyForNewWindow(WebView webView, NSDictionary actionInformation, NSUrlRequest request, string newFrameName, NSObject decisionToken) { this.OpenWeb(request.ToString()); }