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/");
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!
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!
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.
The simplest way I did is, include following script block in an index.html file and remove other code if not required:
<script type="text/javascript">
window.location.href="http://192.168.1.135:3000/";
</script>
And include the host in the ExternalHosts
map in PhoneGap.plist
file, also check OpenAllWhitelistURLsInWebView
is set to YES
in plist file
Setting the wwwFolderName to empty string did not work for me but nil worked.
self.viewController.wwwFolderName = nil;
self.viewController.startPage = @"http://192.168.2.107:9000/";
The simplest way I did is, xxxViewController: CDVViewController<...>
-(void) viewDidLoad{
self.wwwFolderName = @"dist";
self.startPage = @"test.html";
[super viewDidLoad];
}
so,that is all.