【发布时间】:2019-10-05 20:59:59
【问题描述】:
我正在为我的客户开发一个应用程序,并在我的 Xamarin.forms 应用程序中配置了一个 WebView。如何处理错误(如地址无法访问、没有互联网等。)
我添加了try 子句并捕获异常。但它不起作用,如果没有互联网,默认的无法访问页面出现在 android 和 iOS 上的空白页面
try{WebView.Source = "http://viva-t.000webhostapp.com/vivaapp";}
catch (Exception){var htmlSource = new HtmlWebViewSource();
htmlSource.Html = @"<html><body><h1>An Error!!!!</h1><p>Could not be loaded</p></body></html>";
WebView.Source = htmlSource;}
我希望“无法加载此页面”,但我看到的是原始的 android 错误页面:“net::ERR_ADDRESS_UNREACHABLE”
【问题讨论】:
-
可以通过'OnNavigating'事件拦截url,然后进行相应处理。
-
你能用代码回答它吗..
标签: c# xamarin.forms webview