【发布时间】:2015-04-17 22:15:53
【问题描述】:
当应用程序在后台打开时收到警报消息。当我在启动应用程序时从后台关闭应用程序时,它不会给我警报消息。首次启动应用时,handleOpenURL 无法在 JavaScript 中调用。以下是代码
didFinishLaunchingWithOptions 代码
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);
}
请帮帮我。
【问题讨论】:
-
它正在使用 Cordova 3.6 版本。在更高版本 3.7 cordova 中不工作
-
尝试将 setTimeout 从 1 增加到 1000,看看问题是否仍然存在。第一次尝试时,我感觉 webview 没有完全加载。
标签: javascript ios phonegap-build