我尝试使用Cleaver,即PhoneGap / Cordova作为现有iOS应用程序的一个组件.我跟着 this step by step guide两次,没有成功. 我的应用程序可以轻松实例化Web视图,我可以使用stringbyevaluatingjavascriptfromstr
我的应用程序可以轻松实例化Web视图,我可以使用stringbyevaluatingjavascriptfromstring方法将内容传递给它,但是一旦我尝试访问PhoneGap API(navigator.compass,navigator.network,…),似乎没有任何工作. console.log(navigator)没有显示Cordova对象的迹象(console.log不输出任何东西是Xcode,我使用的是http://debug.phonegap.com/). deviceready事件也未触发.
在我的html文件中,我包含我从另一个项目复制的PhoneGap js文件cordova-1.7.0rc1.js(因为当使用PhoneGap作为组件时/ www文件夹丢失).
我的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
你知道发生了什么吗?任何帮助将不胜感激 !
好吧,经过几个小时试图解决这个问题,我终于发现了什么问题.这是搞砸事情的路线:
cdvViewController.webView.delegate = self;
您不能只覆盖视图控制器的Web视图的委托.原始委托具有实例化代码,可以使PhoneGap运行.不要覆盖它,一切都会好的!
