1

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

4

1 回答 1

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 ];
     }
 }
于 2012-04-13T03:54:33.880 回答