UIWebView:在Safari中打开一些链接,在视图中打开一些链接 [英] UIWebView: open some links in Safari, some within the view

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

问题描述

我的应用程序具有内容(出于文本格式原因)显示在UIWebView中的内容。在内容中有链接,其中一些应在移动Safari中打开其目标,而另一些应在内容中导航。

My app features content that (for text formatting reasons) is presented in an UIWebView. Within the content there are links, some of which should open their target in mobile Safari, while others should navigate within the content.

到目前为止,我已经掌握了链接使用UIWebView委托的请求。在我的实现中

So far, I've catched the link requests using a UIWebView delegate. In my implementation of

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

我将使用 lastPathComponent pathComponents 来确定是在外部还是在视图内打开链接。

I'd check the requests URL using lastPathComponent or pathComponents for known elements to determine whether to open the link externally or within the view.

但是,我刚刚发现上述方法仅在iOS 4.0以后才可用,这会使该应用在iPad上无法使用。另外,我感觉我在这里使用的是肮脏的解决方案。

However, I just found out said methods are only available since iOS 4.0, which would render the app useless on iPad. Plus I have the feeling I'm using a dirty solution here.

还有另一种方法可以某种方式标记我内容中的链接,使它们更容易以便以后在委托方法中处理请求时加以区分?

Is there another way to somehow "mark" the links within my content in a way that makes them easy to distinguish later, when processing the request in the delegate method?

非常感谢!

推荐答案

您可以将URL请求转换为字符串,然后对网站上的子目录进行比较,例如,仅以 http://www.sample.com/myapp/myappswebcontent/ ,以URL的初始子字符串为准。还有什么,发送到Safari。

You could covert the URL request into a string, and do a compare for a subdirectory on your website, such as in URLs that only start with "http://www.sample.com/myapp/myappswebcontent/", against the initial substring of your URL. Anything else, send to Safari.

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

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