简体   繁体   中英

can't get phonegap device.platform to work

I'm using Xcode and trying to get the device's info, but it's not showing up. Here is my code

<!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>

alert (1) pop up, but it just skip alert (2) and alert(status). I'm using PhoneGap 3.0,what am I doing wrong?

steps for installation are at http://docs.phonegap.com/en/3.1.0/cordova_device_device.md.html#Device you need to install plugin (cordova 3+)

    cordova plugin add org.apache.cordova.device

IOS shouldnt require any special configuration in config.xml

check your plugin tag in your config.xml (/config.xml) in you your xcode project. See if 'Device' plug-in is added.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM