【问题标题】:Cordova 2.2 + ChildBrowser 3.0.4 + iOS == FAILCordova 2.2 + ChildBrowser 3.0.4 + iOS == 失败
【发布时间】:2012-11-21 00:52:01
【问题描述】:

我只是想在我的 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。

有什么想法吗?我即将开始寻找一只好山羊或一只好鸡,以快速向“一次编写,到处运行”之神(我相当肯定他们是骗子洛基的后裔)献祭!

【问题讨论】:

    标签: ios cordova childbrowser


    【解决方案1】:

    好的,有几件事。一,个人“DERP!”但其余的我归结为糟糕的文档和奇怪的实现。

    在首页 (https://github.com/alunny/ChildBrowser) 上,.openExternal() 的文档中有一条注释说这是仅限 Android 的。这是我的“笨蛋!”

    (我还没有弄清楚为什么有一个 onOpenExternal 的钩子,据说是 iOS 专用的......)

    其次,抛弃所有告诉您将 childbrowser.js 添加为 ChildBrowser Plugins 项的字符串的文档。您的插件应如下所示:

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

    此问题的要点:

    • target="_blank" 适用于 iPhone 上的 &lt;a&gt; 标签。
    • 确保将 ChildBrowser(字符串)ChildBrowserCommand 项放在插件列表中, childbrowser.js!
    • .openExternal() NOT 对 iPhone 起作用(此时),但 .showWebPage() 起作用(或者,如果你想在 iPhone 上使用 openExternal() 功能,我想你可以在锚标签上设置 target="_blank",并且只为不支持它的平台(如 Android)设置 preventDefault()。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 嘿,谢谢,但这已经在我的 index.html 文件中了。我只是没有把它包括在内,因为我的问题感觉已经足够垃圾了,我认为这是不言而喻的。不过,任何其他想法都会受到欢迎!
      猜你喜欢
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多