我尝试使用Cleaver,即PhoneGap/Cordova作为现有iOS应用程序的组件。我跟着this step by step guide两次,没有成功。Cleaver(PhoneGap/Cordova作为组件)在iOS中不工作
我的应用程序可以很容易地实例化一个Web视图,我可以使用stringbyevaluatingjavascriptfromstring
方法传递的内容,但只要我尝试访问PhoneGap的API(navigator.compass, navigator.network, ...
),似乎没有任何工作。 console.log(navigator)
没有显示科尔多瓦对象的迹象(console.log
不输出任何东西是Xcode,我正在使用http://debug.phonegap.com/)。 deviceready
事件也没有被触发。
在我的html文件中,我包含PhoneGap js文件cordova-1.7.0rc1.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
您有没有发生什么事的想法?任何帮助将不胜感激 !
嗨,那么如果这条线没有添加,webViewDidFinishLoad函数不能被解雇? – red23jordan