Xamarin.iOS开发中,经常使用WebView控件来显示http地址上的内容,但如果你的地址中带有中文参数值,这时候NSUrl是没办法识别的,当你实例化添加NSUrl对象时,返回null,被系统api认为这不是个合法的http地址,这时就需要对url地址进行Uri的utf-8编码操作,这样才能正常使用UIWebView加载地址。
//注意对带中文字字符地址进行URL编码
string url = "";
var uri = new Uri (url);
var nsurl = new NSUrl (uri.GetComponents (UriComponents.HttpRequestUrl, UriFormat.UriEscaped));
webView.LoadRequest (new NSUrlRequest (nsurl));
webView.LoadStarted += delegate {
actView.StartAnimating ();
};
webView.LoadFinished += delegate {
actView.StopAnimating ();
};