简体   繁体   中英

Quasar cordova-plugin-device - error 'device' is not defined

I created a new quasar project, added cordova and played around a little bit.

Everything is working, I can deploy the app on my phone and run it in the emulator.

Right now, I need to get some device information and I wanted to use cordova-plugin-device for that. The plugin is loading, like every plugin I installed. I can see it in the developer window (safari) within the iOS xCode emulator.

Now, I try to get the device information, like it is described in the documentation:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device/index.html

Something like that in the App.vue:

mounted: function () {
    document.addEventListener('deviceready', this.onDeviceReady, false)
  },
  methods: {
    onDeviceReady: function () {
      console.log('cordova', cordova)
      console.log('device', device)
    }
...

But the following error always appears in the console:

error 'device' is not defined no-undef

How can I solve that? I removed the platform already and re-added it.

I am out of ideas and cannot find anything related on the internet.

Thanks in advance Cheers Basti

With the help of the quasar community, I could already solve my problem.

The magic words are: window.device .

Try this

var Type = (navigator.userAgent.match(/iPad/i))  == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i))  == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";

alert(Type);

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