Phone device undefined on Android and iOS

I ran into a problem while using the Phonegap platform. When trying to access any of the device strings, eg. device.name or device.platform, I get undefined. This happens on both iOS and Android. I have set Android permissions in both ApplicationManifest and config.

While researching the problem, I found that the problem might be that the functionality of the device will only be available after 1-3 seconds. I ran some test, set a timeout after 10 seconds, or even performed the action manually via onClick at different times (up to several minutes), but I keep getting undefined.

I tried window.device.name instead of device.name, same result.

Does anyone know why this is happening?

Launching Phonegap 2.3.0 on iOS 6.0.2 and Android 4.1.2

code:

$('#deviceName').html('Name: ' + device.name);
$('#devicePlatform').html('Platform: ' + device.platform);
$('#devicePlatformVersion').html('Version: ' + device.version);

      

Full code here

Your help is appreciated!

+3


source to share


3 answers


"WARNING: device.name

Deprecated as of version 2.3.0. Use instead device.model

.



Refer to the following: http://docs.phonegap.com/en/edge/cordova_device_device.md.html#device.name

+10


source


Function access

Since version 3.0, Cordova implements device-level APIs as plugins. Use the CLI plugin command described in the CLI to add or remove this functionality for a project:



cordova plugin add org.apache.cordova.device

      

As stated in the docs here:
http://docs.phonegap.com/en/edge/cordova_device_device.md.html
or
https://github.com/apache/cordova-plugin-device/blob/master/doc/index. md

+3


source


+1


source







All Articles