Cordova - 已取消尝试访问非Navigator对象上的属性“userAgent” [英] Cordova - Deprecated attempt to access property 'userAgent' on a non-Navigator object

查看:945
本文介绍了Cordova - 已取消尝试访问非Navigator对象上的属性“userAgent”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS 8.1中使用我的Cordova iPhone应用程式。

I'm trying to get my Cordova iPhone app working in iOS 8.1

在7中正常工作,因为8我收到以下错误:

Working fine in 7, since 8 I'm getting the following error:

Deprecated attempt to access property 'userAgent' on a non-Navigator object.

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

This is breaking the rendering of the app in page so I need a fix. I've taken a look at the various proposed solutions around the web but none seem to work.

有趣的是,错误来自于从https://maps.gstatic.com/maps-api-v3/api/js/ 17/17 / main.js 。 - 或许是我要使用的Google Maps API的一部分?

Interestingly the error is coming from the JS retrieved from "https://maps.gstatic.com/maps-api-v3/api/js/17/17/main.js". --- perhaps part of the Google Maps API I'm trying to use?

任何帮助都是惊人的!

非常感谢

Chris

推荐答案

cordova版本是否正在使用?

Which cordova version are you using?

现在应该在最新版本中修复,但是如果不想更新项目,可以将replaceNavigator函数更改为像这样对cordova.js文件(整个是新的)

That should be fixed now in the latest version, but if you don't want to update the project, you can change replaceNavigator function to be like this on the cordova.js file (the whole else is new)

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;
    }

这篇关于Cordova - 已取消尝试访问非Navigator对象上的属性“userAgent”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆