Phonegap handleOpenURL is not called when the application starts (iOS)

Receive a warning message when an application is open in the background. When I close the application from the background when the application starts, it does not give me a message. handleOpenURL cannot reference JavaScript the first time the application is launched. Below is the code

didFinishLaunchingWithOptions Code

NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]; NSString* invokeString = nil; if (url) { invokeString = [url absoluteString]; NSLog(@"iPaperReeder launchOptions = %@", url); } self.viewController.invokeString = invokeString; 

AppDelgate.m

 if (!url) { return NO; } NSString* jsString = [NSString stringWithFormat:@"window.setTimeout(function(){ handleOpenURL(\"%@\"); }, 1)", url]; [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString]; // all plugins will get the notification, and their handlers will be called [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; return YES; 

It should output javascript to this function:

  function handleOpenURL(url) { alert('invoke: ' + url); } 

Please help me.

+7
javascript ios phonegap-build
source share
1 answer

I think you are wrong, follow my code as shown below:

You can easily solve this problem.

In the file "CDVHandleOpenURL.m" you need to change the code as shown below:

 NSString* jsString = [NSString stringWithFormat:@"document.addEventListener('deviceready',function(){if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}});", url]; 

For

 NSString* jsString = [NSString stringWithFormat:@"if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");} else { window._savedOpenURL = \"%@\"; }", url, url]; 

this will work just fine.

Good luck

0
source share

All Articles