从一个UIWebView在Safari Xamarin的iOS C#中打开链接 [英] Xamarin iOS C# Open Links in Safari from UIWebView

查看:715
本文介绍了从一个UIWebView在Safari Xamarin的iOS C#中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#编码一个iPhone应用程序有一个UIWebView,在Xamarin。

I'm coding an iPhone app with a UIWebView, in Xamarin using C#.

由Web视图中默认的嵌入式链接在同一网页打开网页视图。我反而喜欢他们在新的Safari浏览器实例启动链接的页面。

By default embedded links within the web view open a web page in that same web view. I would instead like them to launch the linked page in a new safari browser instance.

这已经回答了对目标C的X代码,但据我所见不是Xamarin C#

This has been answered for objective C in X-Code but as far as I can see not for Xamarin C#

webView.LoadHtmlString(html, new NSUrl(Const.ContentDirectory, true));



在此先感谢

Thanks in advance

亚当

推荐答案

如果内容加载到一个UIWebView并要使用Safari浏览器打开链接,这样做上述的方法将让你一个空白页。您需要检查NavigationType。

If loading content into a UIWebView and you want to use Safari to open links, doing it the way described above will get you a blank page. You need to check the NavigationType.

private bool HandleShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navType)
{
  if (navType == UIWebViewNavigationType.LinkClicked)
  {
    UIApplication.SharedApplication.OpenUrl(request.Url);
    return false;
  }
    return true;
}

这篇关于从一个UIWebView在Safari Xamarin的iOS C#中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆