Force iOS应用程序在Safari中打开外部链接
我有一个iOS应用程序,我使用PhoneGap和JQuery移动。该应用程序有一些外部链接,我想在移动safari打开,但现在,他们只是在应用程序视图中打开。链接如下所示:
I have an iOS app that I made using PhoneGap and JQuery mobile. The app has some external links that I want to open in mobile safari but as of now, they just open in the app view. The links are written like this :
<a rel="external" href="wwww.example.com">Click Here</a>
我阅读JQuery手机文档,并表示添加 rel =external
会解决这个问题,但显然不是。有任何想法吗?请记住,这是一个基于HTML的应用程序。
I read JQuery mobiles docs and it stated that adding rel="external"
would solve this but apparently not. Any ideas? Keep in mind, this is a HTML base app.
最后能够通过导航到MainviewController.m,对于其中提到webView的部分,其他帖子中提到,然后更改从这
Finally was able to do it by navigating to MainviewController.m and looking for a section where it mentioned webView as mentioned in the other posts then changing it from this
/* 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];
}
*/
TO
/**
* 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的经验,所以我不得不尝试这个,所以我很高兴我得到它的工作。
Im have no experience with objective-c so I had to experiment with this so I'm glad I got it to work.