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 中打开链接


基础教程推荐
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 如果条件可以为空 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01