简体   繁体   中英

Ionic 4 native Device plugin returns device uuid null on platform browser

By running ionic cordova run browser device uuid is null as Device object is empty on browser platform.

Device info should be there as it supports browser platform like

platform: browser uuid: "someid"

Here's my code:

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

constructor(private device: Device) { }

console.log('Device UUID is: ' + this.device.uuid);

Result: Device UUID is: null

I'm using @ionic-native/device": "^5.5.0

Please help me out how to resolve this problem. I have tested the code on android device. It's working fine

Sadly the device.uuid property is not supported on the browser platform. See the supported platforms here .

So you might want to check the device.platform beforhand and handle the browser platform differently something like this:

if (this.device.platform === 'browser') {
  console.log('Device UUID is not supported on browser platform');
} else {
  console.log('Device UUID is: ' + this.device.uuid);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM