Javascript 应用程序启动时未调用Phonegap HandleOpeUrl(iOS)
当应用程序在后台打开时获取警报消息。当我启动应用程序时从后台关闭应用程序时,不会向我发送警报消息。当应用程序第一次启动时,handleOpenURL无法在JavaScript中调用。下面是代码 使用选项代码完成启动Javascript 应用程序启动时未调用Phonegap HandleOpeUrl(iOS),javascript,ios,phonegap-build,Javascript,Ios,Phonegap Build,当应用程序在后台打开时获取警报消息。当我启动应用程序时从后台关闭应用程序时,不会向我发送警报消息。当应用程序第一次启动时,handleOpenURL无法在JavaScript中调用。下面是代码 使用选项代码完成启动 NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]; NSString* invokeString = nil; if (url) { invokeString = [url abs
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);
}
请帮帮我。我认为你做得不对,请按照我的代码进行操作,如下所示: 你可以很容易地解决这个问题 在
“CDVHandleOpenURL.m”
文件中,您需要更改代码,如下所示:
NSString* jsString = [NSString stringWithFormat:@"document.addEventListener('deviceready',function(){if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}});", url];
到
这将非常有效
祝您好运使用Cordova 3.6版本可以正常工作。在更高版本3.7 Cordova中不工作请尝试将设置超时从1增加到1000,然后查看问题是否仍然存在。在我看来,当您第一次尝试webview时,它并没有完全加载。
NSString* jsString = [NSString stringWithFormat:@"if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");} else { window._savedOpenURL = \"%@\"; }", url, url];