Cleaver (PhoneGap / Cordova as a component) does not work in iOS

I tried using Cleaver, i.e. PhoneGap / Cordova, as a component of an existing iOS application. I followed this walkthrough twice without success.

My application can easily create a web view, and I can transfer content to it using the stringbyevaluatingjavascriptfromstring method, but as soon as I try to access the PhoneGap API ( navigator.compass, navigator.network, ... ) nothing works. console.log(navigator) does not show any signs of Cordoba objects ( console.log does not display anything, this is Xcode, I use http://debug.phonegap.com/ ). The deviceready event also does not deviceready .

In my html file, I include the PhoneGap file js cordova-1.7.0rc1.js , which I copied from another project (since /www missing a folder when you use PhoneGap as a component).

My ViewController.h imports <Cordova/CDVViewController.h> . Here is my 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 

Do you have any idea what is going on? Any help would be greatly appreciated!

+8
ios cordova
source share
2 answers

Well, after many hours of trying to solve this problem, I finally found what was going wrong. This is the line that messed things up:

 cdvViewController.webView.delegate = self; 

You cannot just override the delegate of the web view of the view manager. The original delegate has an instance code that allows you to launch PhoneGap. Do not cancel it, and everything will be fine!

+1
source share

If you want to be notified of web browsing events without breaking Cordoba, you can try something like this:

 @interface WrappingWebViewDelegate : NSObject <UIWebViewDelegate> @property (nonatomic,retain) id<UIWebViewDelegate> wrappedDelegate; @end @implementation WrappingWebViewDelegate - (void)webViewDidStartLoad:(UIWebView*)theWebView { [self.wrappedDelegate webViewDidStartLoad: theWebView]; // your code } // implement all other delegate methods and forward them to the wrapped delegate [...] @end 

Using:

 cdvViewController = [[CDVViewController alloc] init]; WrappingWebViewDelegate wrappingDelegate = [[WrappingWebViewDelegate alloc] init]; wrappingDelegate.wrappedDelegate = cdvViewController.webView.delegate; cdvViewController.webView.delegate = wrappingDelegate; 

I have not tested this, so you have to be careful.

0
source share

All Articles