我有一个 iOS 应用程序,是我使用 PhoneGap 和 JQuery mobile 制作的。该应用程序有一些我想在移动 safari 中打开的外部链接,但截至目前,它们只是在应用程序 View 中打开。链接是这样写的:
<a rel="external" href="wwww.example.com">Click Here</a>
我阅读了 JQuery 移动文档,它指出添加 rel="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 的经验,所以我不得不尝试这个,所以我很高兴我让它工作了。
关于ios - Force iOS 应用程序在 safari 中打开外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15138721/