I have two scenarios here.
One is, my App is active in the background on my iPad. If I go to safari and click a link with my URL scheme, the App opens and displays an alert with the URL.
This is what I want!
Second scenario is when the App is inactive, and not in the background. Here the App launches, but the alert is never displayed. I can alert the URL out from “didFinishLaunchingWithOptions”, but I need it in my JavaScript function: handleOpenURL(url).
It seems to me that handleOpenURL in my AppDelegate.m is only fired when the App is in the background. Is there any way to make it do the same while not running in the background?
Here is my obj-c handleOpenUrl:
if (!url) { return NO; }
// calls into javascript global function 'handleOpenURL'
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 to this javascript function:
function handleOpenURL(url) {
alert('invoke: ' + url);
}
Now when the App starts initially, it runs didFinishLaunchingWithOptions:
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString* invokeString = nil;
if (url) {
invokeString = [url absoluteString];
NSLog(@"iPaperReeder launchOptions = %@", url);
}
self.viewController.invokeString = invokeString;
Should I modify the didFinishLaunchingWithOptions method, to make it run handleOpenURL?
I figured it out. I was missing a call in the onDeviceReady function: