Tôi đã cố gắng sử dụng Cleaver, đó là PhoneGap/Cordova như một thành phần của một ứng dụng iOS hiện có. Tôi đã theo dõi this step by step guide hai lần mà không thành công.Cleaver (PhoneGap/Cordova là thành phần) không hoạt động trong iOS
Ứng dụng của tôi có thể dễ dàng khởi tạo chế độ xem web và tôi có thể chuyển nội dung sang chế độ xem bằng phương pháp stringbyevaluatingjavascriptfromstring
, nhưng ngay khi tôi cố gắng truy cập API PhoneGap (navigator.compass, navigator.network, ...
) thì không có gì có hiệu quả. console.log(navigator)
cho thấy không có dấu hiệu của các đối tượng Cordova (console.log
không đầu ra bất cứ điều gì là Xcode, tôi đang sử dụng http://debug.phonegap.com/). Sự kiện deviceready
cũng không được kích hoạt.
Trong tệp html, tôi bao gồm tệp PhoneGap js cordova-1.7.0rc1.js
mà tôi đã sao chép từ một dự án khác (vì thư mục /www
bị thiếu khi bạn sử dụng PhoneGap làm thành phần).
My ViewController.h
nhập <Cordova/CDVViewController.h>
. Đây là 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
Bạn có biết ý tưởng gì đang xảy ra không? Mọi sự trợ giúp sẽ rất được trân trọng !
Xin chào, sau đó nếu dòng này không được thêm vào, chức năng webViewDidFinishLoad không thể được kích hoạt? – red23jordan