Cleaver(PhoneGap/Cordova作为组件)无法在iOS中运行

Bra*_*wer 8 ios cordova

我尝试使用Cleaver,即PhoneGap/Cordova作为现有iOS应用程序的一个组件.我按照一步一步的指导两次,没有成功.

我的应用程序可以轻松实例化Web视图,我可以使用该stringbyevaluatingjavascriptfromstring方法将内容传递给它,但是一旦我尝试访问PhoneGap API(navigator.compass, navigator.network, ...),似乎没有任何工作.console.log(navigator)没有显示Cordova对象的迹象(console.log不输出任何东西是Xcode,我正在使用http://debug.phonegap.com/).该deviceready事件也未被触发.

在我的html文件中,我包含cordova-1.7.0rc1.js我从另一个项目复制的PhoneGap js文件(因为/www当您使用PhoneGap作为组件时,文件夹丢失).

我的ViewController.h进口<Cordova/CDVViewController.h>.在这里我的ViewController.m

//
//  ViewController.m
//  CordovaComponent
//

#import "ViewController.h"

@interface ViewController (){
    CDVViewController *cdvViewController ;
}
@end

@implementation ViewController

- (void)pushPhoneGap:(id)sender {

    cdvViewController = [[CDVViewController alloc] init];
    cdvViewController.wwwFolderName = @"www";
    cdvViewController.startPage = @"index.html";
    cdvViewController.view.frame = self.view.bounds;
    cdvViewController.webView.delegate = self;
    [self.navigationController pushViewController:cdvViewController animated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setTitle:@"Push PhoneGap view" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(pushPhoneGap:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(60, 50, 200., 50.);
    [self.view addSubview:button];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSString *jsReturn = [cdvViewController.webView stringByEvaluatingJavaScriptFromString:@"setArray([1, 1, 2, 3, 5, 8, 13, 21, 34, 1]);"];
    NSLog(jsReturn);
}

@end
Run Code Online (Sandbox Code Playgroud)

你知道发生了什么吗?任何帮助将不胜感激 !

Bra*_*wer 1

好吧,经过几个小时的尝试解决这个问题,我终于找到了问题所在。这是把事情搞砸的一行:

cdvViewController.webView.delegate = self;
Run Code Online (Sandbox Code Playgroud)

您不能只覆盖视图控制器的 Web 视图的委托。原始委托具有使 PhoneGap 能够运行的实例化代码。不要覆盖它,一切都会好起来的!