Roeliee
Roeliee

Reputation: 221

Phonegap device is undefined on both android and iOS

While using the Phonegap platform I've ran in to a problem. When trying to access any of the device strings, e.g. device.name or device.platform, I get as value undefined. This occurs on both iOS and Android. I've set the permissions for Android in both the ApplicationManifest and the config.

While doing research into the problem i found that the problem could be the the device functionality will only be available after about 1 to 3 seconds. I've ran some test, set a timeout at 10 seconds or even perform the action manually via onClick at different times (up to several minutes), but i keep getting the undefined value.

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

Does anyone have a clue why this is happening?

Running 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 mush appreciated!

Upvotes: 3

Views: 6882

Answers (3)

realtebo
realtebo

Reputation: 25637

"WARNING: device.name is deprecated as of version 2.3.0. Use device.model instead."

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

Upvotes: 10

Abdullah Adeeb
Abdullah Adeeb

Reputation: 4306

Accessing the Feature

As of version 3.0, Cordova implements device-level APIs as plugins. Use the CLI's plugin command, described in The Command-Line Interface, to add or remove this feature for a project:

cordova plugin add org.apache.cordova.device

As found in the documentations 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

Upvotes: 3

Matt Gaunt
Matt Gaunt

Reputation: 9821

device.model might be what you want.

http://docs.phonegap.com/en/2.3.0/cordova_device_device.model.md.html

Upvotes: 1

Related Questions