Created
March 29, 2012 14:43
-
-
Save shazron/2238079 to your computer and use it in GitHub Desktop.
PhoneGap 1.4.1 hack to load external url - override in MainViewController.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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