Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the device UUID in ionic framework

installed cordova device plugin by :

sudo cordova plugin add org.apache.cordova.device

then downloaded ngCordova and included ng-cordova.min.js in to js folder and also included in index.html

next what i did is injected ngCordova as follows

angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])

then included in controller as follows

angular.module('starter.controllers', [])

.controller('AppCtrl', function($scope, $ionicModal, $timeout, $ionicPlatform,$cordovaDevice)
but still getting the following errors

ReferenceError: device is not defined
at Object.getUUID (http://localhost:8100/js/ng-cordova.min.js:1:14929)
at new <anonymous> (http://localhost:8100/js/controllers.js:27:26)
at invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11591:17)
at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11602:23)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:14906:28
at updateView (http://localhost:8100/lib/ionic/js/ionic.bundle.js:42986:30)
at eventHook (http://localhost:8100/lib/ionic/js/ionic.bundle.js:42933:17)
at Scope.$broadcast (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20605:28)
at $state.transition.resolved.then.$state.transition (http://localhost:8100/lib/ionic/js/ionic.bundle.js:34122:22)
at wrappedCallback (http://localhost:8100/lib/ionic/js/ionic.bundle.js:19197:81)

Can you now tell me what went wrong?

If is there another way to read the Device UUID show me the direction to it.

like image 888
sarsarahman Avatar asked Dec 14 '14 06:12

sarsarahman


People also ask

How do I find the IMEI number on my ionic 4?

Try using Device Plugin that should give you access to a uuid (unique device identifier) - uuid won't always be exactly the IMEI, but it should be unique based on a device. Caveats: for iOS/Android you need to run your app on real devices. you should await for deviceready event before attemting to retrieve device data.

How do I run an ionic app in Visual Studio?

Open Visual Studio 2015 and click File -> New -> Project Option for New Apache Cordova App, using Ionic Framework. New Project Window will open. Subsequently, you can select an Installed -> Template -> Java Script -> Apache Cordova Apps ->Ionic JavaScript Blank. Type Project name as ionic-App1 and click OK button.


1 Answers

Yes, there is another way. You just don't need the ngCordova for this.

When you add the plugin cordova plugin add org.apache.cordova.device it's loaded to your application and therefore the info you want is at window.device.

If you want to get device uuid at anywhere in the code you just need to call window.device.uuid.

If you want as soon as the app starts, then use:

ionic.Platform.ready(function(){
  console.log( window.device.uuid );
});
like image 61
Ratata Tata Avatar answered Sep 17 '22 18:09

Ratata Tata