Reputation: 232
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.
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
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>
Upvotes: 4
Views: 5086
Reputation: 314
In addition to avoisions answer and to avoid path issues like Helmut encountered:
Type in the following into the Terminal/Shell:
cordova plugin add org.apache.cordova.device
Unfortunately one can't distinguish between different devices of the same platform with this method. For example if you'd have to determine if the app is viewed on an iPhone 5 you should probably retrieve the screen size.
Upvotes: 0
Reputation: 232
For a Newbie like me is to mention that the plugin link must be used in the project directory and the .h and .m files of the plugin must be moved into the project plugins directory. Not to forget that the DeviceDetails.js must go into the same directory as the index.js
Upvotes: 0
Reputation: 1235
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
Hopefully that does the trick for you.
Upvotes: 5