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


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01