I'm a complete Phonegap newbie so go easy on me if you can :)
I've got phonegap 1.5 installed and running fine. I struggled to install the childbrowser plugin but I believe it's correctly installed now. However, I can't seem to get the childbrowser to show? I've tried following various tutorials here (http://bit.ly/ifK9lM) and here (http://bit.ly/wOlq6k). I don't get any build errors or console errors but the child browser just doesn't show when I click on a link.
All I get in the console when I click my button is "Opening Url: http://www.google.com". So it's as if it's trying...but I just get no visual output??
I have the ChildBrowser.js file in the root of my www folder alongside the cordova.js file. I have all the Child browser plugin files added to my plugin folder in xcode.
I am using Xcode 3.2.6
If anyone can suggest what I am doing wrong that'd be much appreciated.
I can't post all related code here because it'd just get out of hand. Happy to post requested code.
Here is my current appdelegate.h file:
#import "AppDelegate.h"
#import "MainViewController.h"
#ifdef CORDOVA_FRAMEWORK
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVURLProtocol.h>
#else
#import "CDVPlugin.h"
#import "CDVURLProtocol.h"
#endif
#import "ChildBrowserCommand.h"
#import "ChildBrowserViewController.h"
@implementation AppDelegate
@synthesize invokeString, window, viewController;
//Code excluded for brevity here.....
#pragma UIWebDelegate implementation
- (void) webViewDidFinishLoad:(UIWebView*) theWebView
{
// only valid if FooBar.plist specifies a protocol to handle
if (self.invokeString)
{
NSString* jsString = [NSString stringWithFormat:@"var invokeString = \"%@\";", self.invokeString];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];
}
// Black base color for background matches the native apps
theWebView.backgroundColor = [UIColor blackColor];
return [self.viewController webViewDidFinishLoad:theWebView];
}
- (void) webViewDidStartLoad:(UIWebView*)theWebView
{
return [self.viewController webViewDidStartLoad:theWebView];
}
- (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
return [self.viewController webView:theWebView didFailLoadWithError:error];
}
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest: (NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
- (void) dealloc
{
[super dealloc];
}
@end
Here is my index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0,
maximum-scale=1.0, user-scalable=no;" />
<meta charset="utf-8">
<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
<script type="text/javascript" charset="utf-8" src="ChildBrowser.js"></script>
<script type="text/javascript">
var childBrowser;
function onBodyLoad()
{
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady()
{
childBrowser = ChildBrowser.install();
}
function openChildBrowser(url)
{
try {
childBrowser.showWebPage(url);
}
catch (err)
{
alert(err);
}
}
</script>
</head>
<body onload="onBodyLoad()">
<h1>Hey, it's Cordova!</h1>
<button onclick="openChildBrowser('http://www.google.com');">Open Google</button>
</body>
</html>
Brad
I had the same problem as you and realised it was down to how I added the files to Xcode. Make sure you actually drag the files to the Plugins folder in Xcode - don't just place them in the folder itself.
Also make sure you add the .xib file. If you are following the instructions here: http://blog.digitalbackcountry.com/2012/03/installing-the-childbrowser-plugin-for-ios-with-phonegapcordova-1-5/ he only mentions to add the .h, .m and bundle file but from the screenshot you can see the xib file is there too.
You may also need to upgrade to Xcode 4 - works for me on Xcode 4.2 and Cordova 1.5
You don't need to change anything in the appdelegate file. No imports, no code changes, nothing. Just copy the OS-specific files into the Plugin directory, modify the Cordova.plist file, and copy the JS files into your www folder. And you should be set.
Let me know if this helps - http://blog.digitalbackcountry.com/2012/03/installing-the-childbrowser-plugin-for-ios-with-phonegapcordova-1-5/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With