【问题标题】:Adding functions to Ripple emulator for plugins failing at cordova.exec为在 cordova.exec 失败的插件添加函数到 Ripple 模拟器
【发布时间】:2014-12-24 15:51:27
【问题描述】:

我们正在使用带有多个插件的 Cordova 开发一个移动应用程序,并通过 Ripple 模拟器在 Chrome 中进行检查。显然,有些插件使用了 Ripple 未实现的原生功能,这破坏了 Chrome 中的部分应用功能。

问题:如何给Ripple添加模拟器功能?下面显示了我到目前为止发现的内容以及使其正常工作所缺少的内容。

在控制台中可以看到如下错误:

missing exec:Keyboard.close
ripple.js:40 TypeError: Cannot read property 'close' of undefined
    at ripple.define.module.exports.exec (http://localhost:4428/ripple/assets/ripple.js:40:28665)
    at Function.Keyboard.close (http://localhost:4428/plugins/com.ionic.keyboard/www/keyboard.js:14:2)
    ...

keyboard.js:

exec = require('cordova/exec');
// Line 14, where from the exception stacktrace
exec(null, null, "Keyboard", "close", []);

通过一些谷歌搜索,很明显cordova.exec 是 Javascript 部分和本机后端之间的连接器。我认为,Ripple 应该取代它,并且确实有一个 bridge.js 大概就是这样做的。它甚至具有add() 功能,显然是针对用户提供的模拟器。所以我摸索着,在我的代码中我应该写这样的东西:

var bridge = ripple('platform/cordova/2.0.0/bridge'); 
bridge.add( 
    "Keyboard", 
    { close: function () {} } 
);

唉,ripple 在应用范围内未定义。这是缺少的部分 - 如何访问ripple

【问题讨论】:

    标签: cordova cordova-plugins ripple


    【解决方案1】:

    我也遇到了这个问题以及我能想到的所有问题 - 像这样更改插件的 www 部分:

    var exec    = require('cordova/exec');
    
    // --> here is the start of my code
    
    if (exec.toString().indexOf("emulator") > 0) {
        exec = emulation;
    }
    
    function emulation(success, fail, service, action, args) {
        if (action === "add") {
            var options = args[0];
            alert("Local Notification added: " + options.message);
        }
    }
    
    // --> the end of my code
    

    您对此有何看法?

    可能有人说如何避免这个技巧。 ))

    【讨论】:

    • 感谢您的回答。这就是我们现在所做的。有很多问题:对插件的任何更新/更改都会删除它,我们不希望将插件保存在源代码管理中,所以同样,这个更改没有保存,等等......我会试着理解@cordova@ 和 @ripple@ 究竟是如何相关的。
    • 据我所知,Cordova 对 Ripple 一无所知,但 Ripple 简单了解 Cordova 的主要插件以及如何模拟它们。我对ripple.js 的快速分析并没有帮助我如何扩展Ripple 模拟器。 (((如果你解决了这个问题,能告诉我吗?
    • 我也想加入这个解决方案。最好用ripple和chrome做更多的测试,用模拟器做更少的测试。
    【解决方案2】:

    这是我的完整解决方案:http://www.badpenguin.org/ionic-keyboard-ripple-emulator

    使用 window.parent.ripple 代替。

    还有 close() 还不够;您需要模拟 init() 和其他函数。

    【讨论】:

      猜你喜欢
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 1970-01-01
      相关资源
      最近更新 更多