# Device plugin returning an empty object

**URL:** <https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933>\
**Category:** Ionic Native\
**Created:** [September 11, 2017, 12:11pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933 "2017-09-11T12:11:11Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![HinderiksR](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@HinderiksR](https://forum.ionicframework.com/u/HinderiksR)\
**Post date:** [September 11, 2017, 12:11pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/1 "2017-09-11T12:11:11Z")

</div>

Hi,

I am trying to get device information which there is an plugin for, however it returns just an empty object in both the ios simulator and a actual device.

Any quirks i’m missing ?

With best regards,  
Robin

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 11, 2017, 12:19pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/2 "2017-09-11T12:19:54Z")

</div>

What is your code that returns an empty object?

---

<div class="post-metadata">

**Author:** ![HinderiksR](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@HinderiksR](https://forum.ionicframework.com/u/HinderiksR)\
**Post date:** [September 11, 2017, 12:37pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/3 "2017-09-11T12:37:37Z")

</div>

```auto
import { Device } from '@ionic-native/device';

constructor(public device: Device) {}

check(){
  console.log("Device: ");
  console.log(Device);
  console.log("Info: ");
  console.log(this.device);
}

```

Device is just empty and this.device contains an empty object

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 11, 2017, 12:45pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/4 "2017-09-11T12:45:20Z")

</div>

1. `Device` won’t work, you have to use `this.device`.
2. Wrap the call in platform.ready to make sure the platform is loaded.

---

<div class="post-metadata">

**Author:** ![HinderiksR](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@HinderiksR](https://forum.ionicframework.com/u/HinderiksR)\
**Post date:** [September 11, 2017, 1:12pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/5 "2017-09-11T13:12:06Z")

</div>

```auto
constructor(public http: Http, public network: Network, public device: Device, public platform: Platform, public appVersion: AppVersion, public storage: Storage, public secureStorage: SecureStorage) {
    this.platform.ready().then(() => {
        console.log("This device");
        console.log(this.device);
    });
  }

```

still nothing, this is the constructor of an provider btw

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 11, 2017, 1:15pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/6 "2017-09-11T13:15:44Z")

</div>

Try it in a page or app.component.ts to make sure the provider is not the problem. (I actually don’t know).

---

<div class="post-metadata">

**Author:** ![HinderiksR](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@HinderiksR](https://forum.ionicframework.com/u/HinderiksR)\
**Post date:** [September 11, 2017, 1:46pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/7 "2017-09-11T13:46:04Z")

</div>

That solution also isn’t working. Thank for helping anyway, ill put it up as a bug in github i guess.

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 11, 2017, 1:51pm UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/8 "2017-09-11T13:51:12Z")

</div>

Well, you certainly can, or we can continue debugging this.

Do you have the actual Cordova plugin installed?  
Remote debug the app on your device and then type “device.cordova” or “device” in the console. This object should exist and output some data.

---

<div class="post-metadata">

**Author:** ![HinderiksR](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@HinderiksR](https://forum.ionicframework.com/u/HinderiksR)\
**Post date:** [September 12, 2017, 6:46am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/9 "2017-09-12T06:46:53Z")

</div>

That does indeed return a object with device info (by just calling device in de console) so somehow its not working in the constructor of a page

---

<div class="post-metadata">

**Author:** ![HinderiksR](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@HinderiksR](https://forum.ionicframework.com/u/HinderiksR)\
**Post date:** [September 12, 2017, 7:47am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/10 "2017-09-12T07:47:20Z")

</div>

I tried it on a android device but i could not figure out how to debug it so i just used javascript alert and it showed me the model from the device plugin so i build it for ios and alerted the value there and it also works… it seems like the logging of the object returns an empty one for some reason but using values from it seem to work. This is fine for my because i wanted to use it as a work around for the secure storage plugin not properly functioning on a simulated device.

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 12, 2017, 8:56am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/11 "2017-09-12T08:56:09Z")

</div>

Hm interesting. Are you using with `this.device` now or the global JS object directly from the plugin?

---

<div class="post-metadata">

**Author:** ![HinderiksR](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@HinderiksR](https://forum.ionicframework.com/u/HinderiksR)\
**Post date:** [September 12, 2017, 9:07am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/12 "2017-09-12T09:07:26Z")

</div>

I’m using the this.device now

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 12, 2017, 9:46am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/13 "2017-09-12T09:46:59Z")

</div>

Can you show the code that is now working for you?

---

<div class="post-metadata">

**Author:** ![HinderiksR](https://avatars.discourse-cdn.com/v4/letter/h/9dc877/32.png) [@HinderiksR](https://forum.ionicframework.com/u/HinderiksR)\
**Post date:** [September 12, 2017, 10:00am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/14 "2017-09-12T10:00:27Z")

</div>

i actually don’t use it now because i wanted to use it as a work around for another issue which is solved in another way now. but it basically came down to:

```auto
constructor(public http: Http, public network: Network, public device: Device, public platform: Platform, public appVersion: AppVersion, public storage: Storage, public secureStorage: SecureStorage) {
    this.platform.ready().then(() => {
        console.log(this.device);
        alert(this.device.model);
    });
  }

```

The console log shows an empty object but the alert shows the correct model number (all the other values are also there)

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [September 12, 2017, 10:37am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/15 "2017-09-12T10:37:15Z")

</div>

That is strange, but great if it works.

---

<div class="post-metadata">

**Author:** ![babita112](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/babita112/32/123847_2.png) [@babita112](https://forum.ionicframework.com/u/babita112)\
**Post date:** [January 28, 2019, 11:34am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/16 "2019-01-28T11:34:50Z")

</div>

Hi,

I have tried the same thing and info is alerting but not displaying in the view if i want to display.

---

<div class="post-metadata">

**Author:** ![babita112](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/babita112/32/123847_2.png) [@babita112](https://forum.ionicframework.com/u/babita112)\
**Post date:** [January 28, 2019, 11:49am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/17 "2019-01-28T11:49:44Z")

</div>

Thanks anyways. It is solved. I have fetch one by one every parameter and display in the view. for example:  
this.model = this.device.model;  
this.version = this.device.version;  
this.uuid = this.device.uuid;  
this.isVirtual = this.device.isVirtual;  
this.platform = this.device.platform;  
this.manufacturer = this.device.manufacturer;

---

<div class="post-metadata">

**Author:** ![prashant714](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@prashant714](https://forum.ionicframework.com/u/prashant714)\
**Post date:** [August 22, 2019, 7:48am UTC](https://forum.ionicframework.com/t/device-plugin-returning-an-empty-object/104933/18 "2019-08-22T07:48:43Z")

</div>

I am still getting empty object on alert as well Do any one has any solution?
