强制iOS应用程序在Safari中打开外部链接

我有一个iOS应用程序,我使用PhoneGap和JQuery移动。 该应用程序有一些我想要在移动Safari中打开的外部链接,但截至目前,他们只是在应用程序视图中打开。 链接是这样写的:

<a rel="external" href="wwww.example.com">Click Here</a> 

我阅读JQuery手机文档,它表示,joinrel="external"将解决这个问题,但显然不是。 有任何想法吗? 请记住,这是一个基于HTML的应用程序。

最后是能够做到这一点导航到MainviewController.m并寻找一个部分,其中提到的其他职位中提到的webView然后改变它从这个

 /* Comment out the block below to over-ride */ /* - (void) webViewDidStartLoad:(UIWebView*)theWebView { return [super webViewDidStartLoad:theWebView]; } - (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error { return [super webView:theWebView didFailLoadWithError:error]; } - (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType]; } */ 

对此

 /** * Start Loading Request * This is where most of the magic happens... We take the request(s) and process the response. * From here we can re direct links and other protocalls to different internal methods. */ - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *url = [request URL]; // add any other schemes you want to support, or perform additional // tests on the url before deciding what to do -jm if( [[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) { [[UIApplication sharedApplication] openURL:url]; return NO; } else { return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ]; } } 

我没有经验的Objective-C所以我不得不尝试这个,所以我很高兴我得到它的工作。

尼斯帮了我一些,但它自动打开链接通过把:

 if (navigationType == UIWebViewNavigationTypeLinkClicked) { } 

它的工作,现在当用户点击一个url与http://或https:/ /它在Safari中打开

所以完全我得到这个代码:

 if (navigationType == UIWebViewNavigationTypeLinkClicked) { if( [[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) { [[UIApplication sharedApplication] openURL:url]; return NO; } else { return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ]; } }