No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    New project - cordova-plugin-device - error 'device' is not defined

    Help
    3
    7
    1636
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      Basti last edited by Basti

      Hello,
      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).

      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

      1 Reply Last reply Reply Quote 0
      • metalsadman
        metalsadman last edited by metalsadman

        @Basti I think cordova.plugins.device is the way (for this plugin), i use it in my project, will check later coz im on mobile atm.

        1 Reply Last reply Reply Quote 0
        • B
          Basti last edited by

          @metalsadman Thanks for the fast reply! cordova.plugins is undefined.
          When I look into the cordova_plugins.js

          cordova.define('cordova/plugin_list', function(require, exports, module) {
            module.exports = [
              {
                "id": "cordova-plugin-device.device",
                "file": "plugins/cordova-plugin-device/www/device.js",
                "pluginId": "cordova-plugin-device",
                "clobbers": [
                  "device"
                ]
              },
              {
                "id": "cordova-plugin-splashscreen.SplashScreen",
                "file": "plugins/cordova-plugin-splashscreen/www/splashscreen.js",
                "pluginId": "cordova-plugin-splashscreen",
                "clobbers": [
                  "navigator.splashscreen"
                ]
              }
          

          The “clobbers” are just directly device or navigator.splashscreen.

          I can access navigator.splashscreen but not device.

          1 Reply Last reply Reply Quote 0
          • metalsadman
            metalsadman last edited by metalsadman

            @Basti Hmm look like it’s should be window.dev ice then. Edit. Confirmed i am using window.device.

            1 Reply Last reply Reply Quote 1
            • B
              Basti last edited by Basti

              @metalsadman Thank you SO much! window.device has been the solution! I still don’t really get why, because I can access the rest of the plugins directly but its working like charm!

              You the best!

              Edit: I was already looking into the window object but could not find the device prop, so I was not even trying window.device. Magic happens.

              1 Reply Last reply Reply Quote 0
              • metalsadman
                metalsadman last edited by

                @Basti not all cordova plugins are accessible the same way, some can be on cordova.plugins, navigator, window etc…

                I 1 Reply Last reply Reply Quote 0
                • I
                  iamyohanarias @metalsadman last edited by

                  @metalsadman Hi friend. I’m to trying use the cordova file plugin but on Android I can’t access to cordova.file is undefined. I was put window, navigator, cordova, this.$q.cordova and doesn’t work. I dont know what to do already. Can you help me?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post