How to get the device UUID in ionic framework

If you are using '> ionic serve', device will be "not defined." Try in an emulator or physical device.


Within v2 it works like this:

import { Device } from 'ionic-native';
console.log('Device UUID is: ' + Device.uuid);

Reference: http://ionicframework.com/docs/v2/native/device/


Use ngCordova and cordova Device plugin:

cordova plugin add org.apache.cordova.device

module.controller('MyCtrl', function($scope, $cordovaDevice) {
  var uuid = $cordovaDevice.getUUID();
});

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 );
});