【问题标题】:How can I detect, that my app is running on the Ripple Emulator?如何检测到我的应用程序正在 Ripple Emulator 上运行?
【发布时间】:2014-09-10 11:36:50
【问题描述】:

有没有办法检测我的应用程序当前是在 Ripple Emulator 上运行,而不是在真实设备上运行?我希望一些解决方法代码仅在模拟器上运行。

【问题讨论】:

  • 我创建了一个小的 JS 例程,基于一个 chozen 回复:function isOnRippleEmulator() { if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) { return false; } else { return true; } }

标签: cordova emulation hybrid ripple


【解决方案1】:

您可以检查波纹实例是否可用: if(typeof window.parent.ripple ==="undefined")

如果涟漪是一个对象,涟漪正在运行,否则涟漪不会运行! 快速简单。

试着解释一下:

目标应用在 iframe 中运行。如果涟漪会话已开始,则实例化名为“涟漪”的对象(此时,使对象“涟漪”的原因并不重要)。只需知道对象已创建就足够了。因为有了这些知识,我们就知道应用程序是在涟漪容器中运行的。

使用window.parent,我们可以查询iframe的父节点,在这种情况下,也就是波纹对象所在的波纹环境。

【讨论】:

    【解决方案2】:

    您需要检查navigator 对象中的userAgent 属性,并使用window.parent.ripple 在您的DOM 上检查波纹实例。 Ripple-Emulator 是一个browser userAgent。也许你要添加firefoxOS。 :)

    提示:这不是纹波模拟器的直接情况。它允许在 JavaScript 中检测浏览器或移动设备。

    //check if the application is running on a mobile device or desktop 
    if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/) 
        && !window.parent.ripple) {
        app.deviceType = 'mobile';
    } else {
        app.deviceType = 'browser';
    }
    

    【讨论】:

    • 非常感谢!这确实有效。我基于此创建了一个例程。
    • 不能作为我的 Ripple userAgent 工作:"Mozilla/5.0 (Linux; U; Android 2.3.2; en-us; Nexus S Build/GRH78C) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
    • @MarekCzaplicki 感谢您的反对。过去它确实工作得很好,但似乎涟漪已经改变了。我更新了我的答案,所以它应该对你有用。
    • 我相信检查window.parent.ripple就足够知道了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    相关资源
    最近更新 更多