Skip to content

Instantly share code, notes, and snippets.

@jayproulx
Forked from shazron/gist:2238079
Created April 2, 2012 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayproulx/2287355 to your computer and use it in GitHub Desktop.
Save jayproulx/2287355 to your computer and use it in GitHub Desktop.
PhoneGap 1.4.1 hack to load external url - override in MainViewController.m
// 0. Override these in your MainViewController.m
// 1. your .startPage is http://www.google.com for example, set in your AppDelegate.m
// 2. don't forget to add that url in your whitelist
static BOOL isExternalUrlHack = NO;
- (NSString*) pathForResource:(NSString*)resourcepath;
{
if ([self.startPage isEqualToString:resourcepath] && [self.startPage hasPrefix:@"http://"]) {
isExternalUrlHack = YES;
// return non-nil so it doesn't fail
return resourcepath;
}
return [super pathForResource:resourcepath];
}
- (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
NSLog(@"Failed to load webpage with error: %@", [error localizedDescription]);
/*
if ([error code] != NSURLErrorCancelled)
alert([error localizedDescription]);
*/
if (isExternalUrlHack) {
// load our external url
NSURL* appURL = [NSURL URLWithString:self.startPage];
NSURLRequest *appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
[theWebView loadRequest:appReq];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment