在 Safari 而不是 UIWebVIew 中打开链接? [英] Open links in Safari instead of UIWebVIew?

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

问题描述

我有一个在 UIViewController 内带有 UIWebView 的应用程序.我从 Web 服务加载 HTML 作为字符串,如下所示:

I have an app with a UIWebView inside a UIViewController. I load HTML from a web service as a string like this:

self.webView loadHTMLString:_string baseURL:nil

这个字符串中的 HTML 链接是否可以在浏览器中打开,而不是在我的应用程序的 UIWebView 中打开?我该怎么做?

Is it possible for the HTML links in this string to be opened in the browser and not in the UIWebView in my app? How can I do this?

我已经在托管"UIWebVIew 的 UIViewController 中尝试过这个:

I have tried this in the UIViewController that "hosts" the UIWebVIew:

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
   if (navigationType == UIWebViewNavigationTypeLinkClicked) {
     [[UIApplication sharedApplication] openURL:[request URL]];
     return NO;
   }
   return YES;
}

好像没用……

有什么想法吗?

推荐答案

你设置了 UIWebView 的代理到你的 UIViewController 了吗?据我所知,您的代码没有明显的问题,所以很可能是这样的小问题.

Have you set the delegate of the UIWebView to your UIViewController? There's nothing obviously wrong with your code as far as I can see, so it's likely to be something small like that.

这篇关于在 Safari 而不是 UIWebVIew 中打开链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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