Phonegap 1.5 (Cordova) ios childbrowser doesn't open at all
Asked Answered
T

5

6

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>
Trimble answered 14/3, 2012 at 1:0 Comment(1)
Have you remembered to add the files as group and not reference?Instrumental
P
6

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

Pumice answered 2/4, 2012 at 8:7 Comment(4)
Thanks, you save me a bunch :) the xib file was spot onGlossy
Thanks man, combined with Ryan's link your comments have been very helpful. I think my biggest issue was using an outdated Xcode. All good now. ThanksTrimble
Where is the "Refresh Project" command in Xcode? For the love, I spent an hour on this, and it was all because, even though my files where in the right place, Xcode didn't know to look! Anyway, thank you very much for pointing this out. Works great now!Tormentil
Does anyone know why the .xib is actually needed? I don't see it referenced anywhere in the code.Collocate
F
3

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/

Feudist answered 21/3, 2012 at 0:41 Comment(1)
Thanks for that Ryan, I'm going to accept supermethod's answer as the correct one simply because of the additional info he provided. Thanks very much for your contributon.Trimble
W
0

Try calling the function to show the page like this:

window.plugins.childBrowser.showWebPage(url);

What key and value did you put in your Cordova.plist file? Did you remember the one for external hosts?

Wombat answered 14/3, 2012 at 19:4 Comment(2)
Hi thanks for your answer. I have tried that way and got the same results. Same print out in my console...and nothing appears. I have set my external hosts to "*" for now to allow everything. As far as ChildbrowserEntries go I have the following: Key: ChildBrowserCommand Type: String (default) Value: ChildBrowserCommand Key: ChildBrowser Type: String (default) Value: ChildBrowser.jsTrimble
Is there any definitive answer as to what the proper entries are in Cordova.plist for ChildBrowser?Wombat
B
0

I dont think it Childbrowser works yet with Cordova (1.5).

You should use phonegap 1.4.1. Here you have some examples for 1.4.1: https://github.com/RandyMcMillan/CDVPluginDemos

If anyone has it working with Cordova, please post some examples here:

Broadsword answered 19/3, 2012 at 20:51 Comment(0)
S
0

I'm using the same plugin that Ryan Stewart is using and it does work.He did write a good article on it so check it out. I was able to get it working with the readme files in the plugin folder, there are some slight mods that you have to do.

Also, you may have to upgrade your version of Xcode. For me it worked on 4.2 and now I'm on 4.3.1., but if you're on an earlier version you may have to take the leap

Make sure you've also followed the 'Cordova upgrade' document when installing Cordova itself. Read everything carefully, because this is where I had the problem with installing the plugin and not the plugin itself.

Good luck!

Sparkie answered 1/4, 2012 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.