user1813377
user1813377

Reputation: 21

How to get iOS's Device Model (e.g. "iPhone3,1")?

Is there a way to get the iOS's Device Model / Identifier like "iPhone3,1" within PhoneGap (JavaScript)?

Upvotes: 0

Views: 2933

Answers (3)

Ori
Ori

Reputation: 377

"As of version 3.0, Cordova implements device-level APIs as plugins."

you must first install the plugin (from the project home directory): cordova plugin add org.apache.cordova.device

Here is a sample code for using it:

 <!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, false);

    // device APIs are available
    //
    function onDeviceReady() {
        var element = document.getElementById('deviceProperties');
        element.innerHTML = 'Device Model: '    + device.model    + '<br />' +
                            'Device Cordova: '  + device.cordova  + '<br />' +
                            'Device Platform: ' + device.platform + '<br />' +
                            'Device UUID: '     + device.uuid     + '<br />' +
                            'Device Version: '  + device.version  + '<br />';
    }

    </script>
  </head>
  <body>
    <p id="deviceProperties">Loading device properties...</p>
  </body>
</html>

PhoneGap Documentation

When you have the plugin installed, you can than read the device model via: window.device.model

Don't forget to call it after deviceready event and don't forget to load the cordova.js There is still a problem that the device reported is not accurate. I tested it on various IOS devices and I get the following results:

iPhone 4 is reported as iPhone3,1

iphone 5s is reported as iPhone6,2

iPhone 6 Plus is reported as iPhone 7,1

iPad 2 is reported as iPad3,3

I now investigate to understand what these values mean. If anyone has a clue I will be happy to hear.

Upvotes: 1

grg
grg

Reputation: 5874

In Cordova (PhoneGap) 2.3.0, this is possible without any plugins using device.model

For all platforms, there is a new property called device.model — this returns the specific device model, e.g “iPad2,5″ (for other platforms, this returns what device.name used to return).

Source

Upvotes: 1

Raymond Camden
Raymond Camden

Reputation: 10857

Yep, via the Device API. You can access them via window.device.*. Here is a list of the properties:

device.name
device.cordova
device.platform
device.uuid
device.version

Upvotes: 1

Related Questions