ios - phone gap 1.6.0 打开外部链接

标签 ios cordova

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

最佳答案

找到解决方案

MainViewController.m 中取消注释此 block

/* 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 ];
     }
 }

关于ios - phone gap 1.6.0 打开外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10118649/

相关文章:

ios - 如何将事件处理程序 block 放在自定义类上

iphone - 如何在 iPhone 的 MKAnnotationView 中的标题下显示图像

ios - "initialize"Swift 类的类方法?

iphone - 如何在iPhone的工具栏上添加分段控件

javascript - 捕获音频并上传

android - 在 cordova 插件中获取上下文

android - 使用 Cordova 执行 aapt 失败

ios - MKMapView检测点击坐标处是否有POI

javascript - 在phonegap应用程序中将数据库保存在哪里

ios - 如何从 ionic/cordova/phonegap 中的布局截取屏幕截图?