Xamarin iOS C# Open Links in Safari from UIWebView(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 中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Xamarin iOS C# 从 UIWebView 在 Safari 中打开链接


基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01