Cordova / phonegap 3.0 device properties

I'm new to phonegap / cordova 3.0, and it looks like I have a similar problem with PhoneGap Help: device properties, cordova v phonegap, xcode debugging . Unfortunately, I have not yet been able to find a solution on the Internet.

After creating the Hello World for iOS example, everything works fine in the simulator. But after changing the contents in index.html with the example code provided for the device properties in the den documentation, the simulator screen shows only โ€œLoading device propertiesโ€. Nothing more. For some reason, the onDeviceReady () function is not working properly. Any help is much appreciated

Here is the index.html code for 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> 

screenhot of xcode and simulator

+4
source share
3 answers

As I mentioned in another question that you contacted, I think the problem here may be with a missing plugin. Your onDeviceReady function should work (try throwing a warning there just to test it) ... but I think you might run into problems when trying to access things like device.model and device.version.

To access the device object, you need to install the plugin. Copying in sample code will not work without a plugin. If you have not already done so, grab the plugin using:

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

Hope this helps you.

+5
source

For beginners like me, it is worth mentioning that the link to the plugin should be used in the project directory, and the .h and .m files for the plugin should be moved to the project plugins directory. Remember that DeviceDetails.js must go to the same directory as index.js

0
source

In addition to rejection responses, and avoid content issues like Helmut:

  • Open terminal / shell
  • Go to your Phonegap project directory ($ cd path / to / project)
  • Enter the following into the terminal / shell:

    cordova plugin add org.apache.cordova.device

Unfortunately, it is impossible to distinguish different devices of the same platform from this method. For example, if you need to determine if an application is being viewed on an iPhone 5, you should probably get a screen size.

0
source

Source: https://habr.com/ru/post/1499413/


All Articles