【发布时间】:2012-06-29 15:40:48
【问题描述】:
我尝试使用 Cleaver,即 PhoneGap / Cordova 作为现有 iOS 应用程序的组件。我关注了this step by step guide 两次,都没有成功。
我的应用程序可以轻松地实例化一个 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
你知道发生了什么吗?任何帮助将不胜感激!
【问题讨论】: