无法获得phonegap device.platform工作

子維 *_*維 宋 5 javascript cordova

我正在使用Xcode并尝试获取设备的信息,但它没有显示出来.这是我的代码

<!DOCTYPE html>
<html>
<head>
    <title>Device Properties Example</title>

    <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, true);

        // device APIs are available


        function onDeviceReady() {
            alert('1');
            var status = device.platform;
            alert('2');
            alert(status);
            $("#deviceProperties").html(status) ;}

        </script>
</head>
<body>
    <p id="deviceProperties">Loading device properties...</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

警报(1)弹出,但它只是跳过警报(2)和警报(状态).我正在使用PhoneGap 3.0,我做错了什么?

小智 10

安装步骤在 http://docs.phonegap.com/en/3.1.0/cordova_device_device.md.html#Device, 你需要安装插件(cordova 3+)

    cordova plugin add org.apache.cordova.device
Run Code Online (Sandbox Code Playgroud)

IOS不应该在config.xml中需要任何特殊配置


Har*_*rdy 4

检查 xcode 项目中 config.xml (/config.xml) 中的插件标签。查看是否添加了“设备”插件。

<widget>
...
<plugins>
    <plugin name="Device" value="CDVDevice" />

    <plugin name="Logger" value="CDVLogger" />
    <plugin name="Compass" value="CDVLocation" />
    <plugin name="Accelerometer" value="CDVAccelerometer" />
    <plugin name="Camera" value="CDVCamera" />
    <plugin name="NetworkStatus" value="CDVConnection" />
    <plugin name="Contacts" value="CDVContacts" />
    <plugin name="Debug Console" value="CDVDebugConsole" />
    <plugin name="Echo" value="CDVEcho" />
    <plugin name="File" value="CDVFile" />

    ...
</plugins>
</widget>
Run Code Online (Sandbox Code Playgroud)