Cordova - 不推荐尝试在非Navigator对象上访问属性"userAgent"

Chr*_*ris 5 javascript google-maps ios cordova

我正在尝试让我的Cordova iPhone应用程序在iOS 8.1中运行

工作正常7,自8以来我收到以下错误:

Deprecated attempt to access property 'userAgent' on a non-Navigator object.
Run Code Online (Sandbox Code Playgroud)

这打破了页面中应用程序的渲染,所以我需要修复.我已经看过网络上提出的各种解决方案,但似乎都没有.

有趣的是,错误来自于从" https://maps.gstatic.com/maps-api-v3/api/js/17/17/main.js "中检索到的JS .---也许是我试图使用的Google Maps API的一部分?

任何有关此事的帮助都会令人惊叹!

非常感谢

克里斯

jce*_*ile 14

你使用哪种cordova版本?

现在应该在最新版本中修复,但是如果你不想更新项目,可以在cordova.js文件中更改replaceNavigator函数(其他全新内容)

function replaceNavigator(origNavigator) {
        var CordovaNavigator = function() {};
        CordovaNavigator.prototype = origNavigator;
        var newNavigator = new CordovaNavigator();
        // This work-around really only applies to new APIs that are newer than Function.bind.
        // Without it, APIs such as getGamepads() break.
        if (CordovaNavigator.bind) {
            for (var key in origNavigator) {
                if (typeof origNavigator[key] == 'function') {
                    newNavigator[key] = origNavigator[key].bind(origNavigator);
                } else {
                    (function(k) {
                        Object.defineProperty(newNavigator, k, {
                            get: function() {
                                return origNavigator[k];
                            },
                            configurable: true,
                            enumerable: true
                        });
                    })(key);
                }
            }
        }
        return newNavigator;
    }
Run Code Online (Sandbox Code Playgroud)