当应用程序在后台打开时获取警报消息.当我启动应用程序时从后台关闭应用程序时,它不会给我提示警报消息.当应用程序首次启动时,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;
function handleOpenURL(url) { alert('invoke: ' + url); }
请帮我.
解决方法
我认为你做得不对,请按照我的代码如下:
您可以轻松解决此问题.
在“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];
这将完美地运作.
祝你好运