gpt4 book ai didi

javascript - 应用程序启动时未调用 Phonegap handleOpenURL (iOS)

转载 作者:可可西里 更新时间:2023-11-01 03:35:00 24 4
gpt4 key购买 nike

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

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];

这将完美地工作。

祝你好运

关于javascript - 应用程序启动时未调用 Phonegap handleOpenURL (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28557754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com