cordova / phonegap 3.0设备属性 [英] cordova / phonegap 3.0 device properties

查看:131
本文介绍了cordova / phonegap 3.0设备属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的phonegap / cordova 3.0,似乎我有一个类似的问题, PhoneGap帮助:设备属性,cordova v phonegap,xcode调试
现在不能在互联网上找到解决方案。

I am new to phonegap / cordova 3.0 and it seems that I have a similar problem as PhoneGap Help: device properties, cordova v phonegap, xcode debugging. Unfortunately I couldn't find a solution in the internet by now.

在为ios创建了Hello World示例后,一切都在模拟器中正常工作。但在改变index.html中的内容与在den文档中为设备属性给出的示例的代码,模拟器的屏幕只显示加载设备属性..没有更多。
由于某种原因,onDeviceReady()函数不能正常工作。
任何帮助都非常感谢

After having created the Hello World example for ios everything works fine in the simulator. But after having changed the content in the index.html with the code of the example given for device properties in den documentation the screen of the simulator shows only "Loading device properties.." Nothing more. For some reason the function onDeviceReady() does not work properly. Any help is highly appreciated

以下是设备属性的index.html的代码

Here is the code of index.html for the device properties

<!DOCTYPE html>



设备属性示例

Device Properties Example

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

        // Wait for device API libraries to load
        //
        document.addEventListener("deviceready", onDeviceReady, false);

        // device APIs are available
        //
        function onDeviceReady() {
            var element = document.getElementById('deviceProperties');
            element.innerHTML = 'Device Name: '     + device.name     + '<br />' +
            'Device Cordova: '  + device.cordova  + '<br />' +
            'Device Platform: ' + device.platform + '<br />' +
            'Device UUID: '     + device.uuid     + '<br />' +
            'Device Model: '    + device.model    + '<br />' +
            'Device Version: '  + device.version  + '<br />';
        }

        </script>
</head>
<body>
    <p id="deviceProperties">Loading device properties...</p>
</body>

推荐答案

正如我在你链接到的另一个问题中提到的,我认为这里的问题可能是一个缺少的插件。您的 onDeviceReady 函数应该正常工作(尝试在其中引发警报,只是为了测试它)...但我想你可能会遇到问题,当你尝试访问 device.model device.version

As I mentioned in the other question you linked to, I think the issue here may be with a missing plugin. Your onDeviceReady function should be working (try throwing an alert in there, just to test it out)... but I think you may be running into issues when you're trying to access things like device.model and device.version.

要访问设备对象,需要安装插件。如果没有插件,在示例代码中复制将无法工作。如果你还没有这样做,使用插件:

In order to access the device object, you need to install the plugin. Copying in the example code won't work without the plugin. If you haven't done so already, grab the plugin using:

$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

希望窍门。

这篇关于cordova / phonegap 3.0设备属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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