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

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

问题描述

我正在使用 C# 在 Xamarin 中使用 UIWebView 编写 iPhone 应用程序.

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

默认情况下,Web 视图中的嵌入链接会在同一 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.

X-Code 中的目标 C 已经回答了这个问题,但据我所知,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));

提前致谢

亚当

推荐答案

如果将内容加载到 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;
}

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

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