簡體   English   中英

如何處理Xamarin.forms Webview中的加載錯誤

[英]How to handle load errors in Xamarin.forms webview

我正在為我的客戶端開發一個應用程序,並已在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”

嘗試在webview導航事件中按以下方式處理錯誤。

  var htmlSource = new HtmlWebViewSource();
  htmlSource.Html = @"<html><body><h1>An Error!!!!</h1><p>Could not be loaded</p></body></html>";
  var wb = new WebView();
  wb.Source = htmlSource;
  wb.Navigated += (s, e) =>
  {
    if(e.Result!= WebNavigationResult.Success)
    {
         //Handle error here!
    }
  };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM