在手机缺口1.6.0中打开外部链接

时间:2012-04-12 06:40:55

标签: ios cordova

如何使用最新版本的phonegap打开iOS内部的外部链接?

1 个答案:

答案 0 :(得分:1)

找到解决方案

MainViewController.m

中取消注释此块
/* 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];
}
*/

并替换此完整功能

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

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
 {
     NSURL *url = [request URL];
     if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) 
     {
        return YES;
     }
     else {
        return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
     }
 }