Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 412
子維 宋 Avatar asked Aug 26 '13 01:08

子維 宋


People also ask

What is PhoneGap plugin?

Apache Cordova and Adobe PhoneGap provide a way for developers to develop apps for all major platforms in HTML, CSS and JavaScript. Developers only have to maintain a single codebase for all platforms. The project started out as PhoneGap and when it was acquired by Adobe the code was released as Apache Cordova.


2 Answers

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

like image 50
kate Avatar answered Oct 03 '22 14:10

kate


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>
like image 43
Hardy Avatar answered Oct 03 '22 15:10

Hardy