Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an external startpage with Cordova 1.6 on iOS

is it possible to load an external index.html (with included cordova.js) instead of the local one?

i found in the appdelegate.m this code:

self.viewController.wwwFolderName = @"www";
self.viewController.startPage = @"index.html";

i tried to reference an external url but without luck... anyone know a solution for this?

p.s.

with android it's easy:

super.loadUrl("http://192.168.1.135:3000/");
like image 427
marcus3006 Avatar asked Apr 23 '12 08:04

marcus3006


3 Answers

I have done this for my project (AppDelegate.m):

self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES; // YES;
self.viewController.wwwFolderName = @""; // @"www";
self.viewController.startPage = @""; // @"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;

// Load request with new root URL
NSURL *urlOverwrite = [NSURL URLWithString:@"http://kyryll.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:urlOverwrite];

[self.viewController.webView loadRequest:request];

As mentioned elsewhere, the site you are trying access has to be whitelisted.

It's working nicely. My external site is on local IIS and has the cordova.js as well as few plugins. Now just have to see if I get Apple to approve my app!

like image 98
Kyryll Tenin Baum Avatar answered Nov 13 '22 11:11

Kyryll Tenin Baum


If you include the PhoneGap source as a subproject (I used 1.7 and the directions still worked, see my note at the end), you can add a few lines of code to allow PhoneGap to support external URLs as the startPage.

Around line 133, you'll want to add

if([self.startPage hasPrefix:@"http"]) {
    appURL = [NSURL URLWithString:self.startPage];
}
else 

right before if (startFilePath == nil) {

By default, PhoneGap doesn't seem to support external startPage URLs without a javascript 'hack' mentioned above. Other than this (and that), I know no other way!

Let me know if you have more questions.

Note: as I mentioned above, the walkthrough is missing one step. I commented on the article to let the author know, but it hasn't been approved yet. Below is my comment:

A step that was missing for me was adding $(CORDOVALIB)/Classes to the Header Search Path under Build Phases (also marking it to recursively search). Other than that, great write up!

like image 43
forrestranger Avatar answered Nov 13 '22 09:11

forrestranger


For iOS it would be:

self.viewController.wwwFolderName = @""; // @"www"
self.viewController.startPage = @"http://192.168.2.107:9000/";

The names are confusing because the startPage is also the URL.

like image 2
Stephan Froede Avatar answered Nov 13 '22 09:11

Stephan Froede