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
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
What is your code that returns an empty object?
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
Device
won’t work, you have to use this.device
.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
Try it in a page or app.component.ts to make sure the provider is not the problem. (I actually don’t know).
That solution also isn’t working. Thank for helping anyway, ill put it up as a bug in github i guess.
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.
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
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.
Hm interesting. Are you using with this.device
now or the global JS object directly from the plugin?
I’m using the this.device now
Can you show the code that is now working for you?
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:
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)
That is strange, but great if it works.
Hi,
I have tried the same thing and info is alerting but not displaying in the view if i want to display.
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;
I am still getting empty object on alert as well Do any one has any solution?