Cordova 2.2+儿童浏览器3.0.4+iOS==失败



我只是想在我的PhoneGap应用程序中设置一个函数,在外部浏览器中打开某些链接。该代码似乎在Android上运行良好(我没有在Windows Phone上进行测试,因为插件信息声称还没有支持…),但每次我试图在iPhone模拟器(iOS 5.1)中运行时,它都会出现以下错误:

testCB[3332:c07] CDVPlugin class childbrowser.js (pluginName: ChildBrowser) does not exist.
testCB[3332:c07] ERROR: Plugin 'ChildBrowser' not found, or is not a CDVPlugin. Check your plugin mapping in Cordova.plist.
testCB[3332:c07] -[CDVCommandQueue executePending] [Line 102] FAILED pluginJSON = ["ChildBrowser1249404349","ChildBrowser","showWebPage",["http://www.apple.com",{"showLocationBar":true}]]

我浏览了所有的论坛和这里,我不断看到有人提到更新Cordova.plist文件。好吧,就是这样(注意,这是一个全新的Cordova应用程序,而不是升级或更新,我现在正在用一个测试应用程序来尝试,以排除我自己的应用程序中的不稳定因素):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- the standard keys snipped -->
<key>ExternalHosts</key>
<array>
<string>*</string>
</array>
<key>Plugins</key>
<dict>
<key>ChildBrowser</key>
<string>childbrowser.js</string>
<key>ChildBrowserCommand</key>
<string>ChildBrowserCommand</string>
<key>Device</key>
<string>CDVDevice</string>
<key>Logger</key>
<string>CDVLogger</string>
<key>Compass</key>
<string>CDVLocation</string>
<key>Accelerometer</key>
<string>CDVAccelerometer</string>
<key>Camera</key>
<string>CDVCamera</string>
<key>NetworkStatus</key>
<string>CDVConnection</string>
<key>Contacts</key>
<string>CDVContacts</string>
<key>Debug Console</key>
<string>CDVDebugConsole</string>
<key>Echo</key>
<string>CDVEcho</string>
<key>File</key>
<string>CDVFile</string>
<key>FileTransfer</key>
<string>CDVFileTransfer</string>
<key>Geolocation</key>
<string>CDVLocation</string>
<key>Notification</key>
<string>CDVNotification</string>
<key>Media</key>
<string>CDVSound</string>
<key>Capture</key>
<string>CDVCapture</string>
<key>SplashScreen</key>
<string>CDVSplashScreen</string>
<key>Battery</key>
<string>CDVBattery</string>
<key>Globalization</key>
<string>CDVGlobalization</string>
</dict>
</dict>
</plist>

(编辑)在我的index.html文件中,我包含了(我意识到这几乎是不言而喻的。我也意识到很多问题是由那些不想先尝试所有显而易见的东西的人发布的!):

<script type="text/javascript" src="cordova-2.2.0.js"></script>
<script type="text/javascript" src="childbrowser.js"></script>

我的js调用看起来像:

onDeviceReady: function() {
app.receivedEvent('deviceready');
var link = document.getElementById('launchApple');
console.log('derp?');
if(link){
//var cb = ChildBrowser.install();
console.log("We're trying to add a click handler link");
link.addEventListener('click', function() {
console.log('click');
window.plugins.childBrowser.openExternal('http://www.apple.com'); });
}
},

当我点击链接时,我会得到上面的错误。

我已经尝试将childbrowser.js文件的大小写更改为childbrowser.js。我试过在iPhone 6模拟器中运行它。我的插件文件夹包含从https://github.com/alunny/ChildBrowser

我已从~/Library/Application Support中清除缓存我在这个项目上试过Clean。

有什么想法吗?我即将开始寻找一只好山羊或鸡,作为对"写一次,到处跑"神的快速牺牲(我很确定他们是骗子洛基的后代)!

好的,有几件事。一个是个人的"DERP!",但我认为剩下的只是糟糕的文档和奇怪的实现。

在头版(https://github.com/alunny/ChildBrowser),.openExternal()的文档中有一条注释,说这只是Android。这是我的"derp!">

(我还没有弄清楚为什么会有一个onOpenExternal的钩子,它被称为仅iOS…)

其次,抛出所有告诉您添加childbrowser.js作为childbrowser插件项字符串的文档。你的插件应该看起来像:

<key>ChildBrowser</key>
<string>ChildBrowserCommand</string>
<key>ChildBrowserCommand</key>
<string>ChildBrowserCommand</string>

这个问题的收获:

  • target="_blank"适用于iPhone上的<a>标签
  • 请确保将ChildBrowser(字符串)ChildBrowserCommand项放在插件列表中,NOTChildBrowser.js
  • .openExternal()对iPhone不起作用,但.showWebPage()起作用(或者,如果你想在iPhone上使用openExternal(()功能,我想你可以在锚点标签上设置target="_blank",只对不支持它的平台(如Android)设置preventDefault())

cordova.js脚本之后,将childbrowser.js添加到HTML文件中,如下所示:

<script type="text/javascript" src="childbrowser.js"></script>

最新更新