gpt4 book ai didi

ios - Cordova 2.3 Phonegap InAppBrowser URL 白名单错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:21 25 4
gpt4 key购买 nike

Cordova 2.3.0 中的 InAppBrowser 无法正确加载 URL。我知道这与白名单 URL 的新方法有关,以及它们如何仅适用于主 Cordova WebView 而不是插件。

我读过 an article关于如何使用插件的白名单 URL,但它非常模糊,我不确定在哪里添加他们建议的代码。

上述链接中第 3 步的说明建议:

Step 3). Network connections by plugins are no longer checked by the whitelist. To use the whitelist for your plugin network connections, you have to set the "User-Agent" header of your connection to the user-agent of the viewController.

`CDVViewController* vc = ((CDVViewController*)self.viewController);
NSString* userAgent = vc.userAgent;
// then set the User-Agent header of your network connection...`

文章并没有说在哪里添加这段代码。我假设它在 MainViewController.m 中,但我不确定。我试过将它放在该文件的 init 函数中,但没有用。我也不知道他们所说的“然后设置网络连接的 User-Agent header ...”是什么意思,我应该在哪里设置它?

有人成功过吗?如果是这样,我会喜欢一些帮助。我真的被困在这里了。

谢谢!

最佳答案

我一直收到 webView:didFailLoadWithError 的原因是因为传入的 URL 没有经过编码。像 google.com 这样的常规 URL 工作正常,但带有参数的更复杂的 URL 会导致加载错误。解决方法是在调用 window.open 之前对 URL 进行编码:

var URL = encodeURI(e.data.url);
var ref = window.open(URL, '_blank', 'location=yes');

这解决了使用 Cordova 2.5 的问题。

关于ios - Cordova 2.3 Phonegap InAppBrowser URL 白名单错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14416294/

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