应用程序启动时没有调用Phonegap handleOpenURL(iOS)

时间:2015-02-17 08:37:46

标签: javascript ios phonegap-build

在应用程序在后台打开时收到警报消息。当我启动应用程序时从后台关闭应用程序时,它不会给我提示警报消息。当应用程序首次启动时,handleOpenURL无法在JavaScript中调用。以下是代码

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;

应该输出到这个javascript函数:

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

请帮帮我。

1 个答案:

答案 0 :(得分:0)

我认为你做得不对,请按照我的代码进行操作:

您可以轻松解决此问题。

"CDVHandleOpenURL.m"文件中,您需要更改以下代码:

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

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

这将完美地运作。

祝你好运