Skip to content

Instantly share code, notes, and snippets.

@kapejod
Created April 23, 2015 17:53
Show Gist options
  • Save kapejod/85bd38cd74971741ee15 to your computer and use it in GitHub Desktop.
Save kapejod/85bd38cd74971741ee15 to your computer and use it in GitHub Desktop.
Fix handleOpenURL() for Cordova on iOS (cold + warm start)
--- CDVViewController.m.orig 2015-04-23 19:49:35.000000000 +0200
+++ CDVViewController.m 2015-04-23 19:47:51.000000000 +0200
@@ -44,6 +44,7 @@
@property (readwrite, assign) BOOL initialized;
@property (atomic, strong) NSURL* openURL;
+@property (atomic) BOOL pageLoaded;
@end
@@ -83,6 +84,7 @@
[self printMultitaskingInfo];
[self printPlatformVersionWarning];
self.initialized = YES;
+ self.pageLoaded = NO;
// load config.xml settings
[self loadSettings];
@@ -1000,21 +1002,16 @@
- (void)onPageDidLoad:(NSNotification*)notification
{
+ self.pageLoaded = YES;
if (self.openURL) {
- [self processOpenUrl:self.openURL pageLoaded:YES];
+ [self processOpenUrl:self.openURL];
self.openURL = nil;
}
}
-- (void)processOpenUrl:(NSURL*)url pageLoaded:(BOOL)pageLoaded
+- (void)processOpenUrl:(NSURL*)url
{
- if (!pageLoaded) {
- // query the webview for readystate
- NSString* readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
- pageLoaded = [readyState isEqualToString:@"loaded"] || [readyState isEqualToString:@"complete"];
- }
-
- if (pageLoaded) {
+ if (self.pageLoaded) {
// calls into javascript global function 'handleOpenURL'
NSString* jsString = [NSString stringWithFormat:@"if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}", url];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
@@ -1024,11 +1021,6 @@
}
}
-- (void)processOpenUrl:(NSURL*)url
-{
- [self processOpenUrl:url pageLoaded:NO];
-}
-
// ///////////////////////
- (void)dealloc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment