当应用程序在后台打开时获取警报消息.当我启动应用程序时从后台关闭应用程序时,它不会给我提示警报消息.当应用程序首次启动时,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); }
请帮我.
解决方法
我认为你做得不对,请按照我的代码如下:
您可以轻松解决此问题.
在“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];
这将完美地运作.
祝你好运
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。