Ionic Cordova Device UUID

Hi i am developing a hybrid app using the Ionic framework and Cordova. I am looking to use the device uuid as an ID so i have added the cordova device plugin. Additionally i am using the NG-Cordova wrapper for calling my cordova plugins. However whenever i run my app in the xcode Simulator or on an actual Ipad all i get is {{uuid}} .

There does not seem to be any error message i can only assume that the Device Plugin is not working.

i have put my code below however im not sure this is the issue, Has anyone had this issue before and if so how did they work around it?

Controller:

angular.module(‘starter.controllers’, )

.controller(‘DashCtrl’, function ($scope, $state, $cordovaDevice) {

var init = function () {
  console.log("initializing device");
  try {
    $scope.uuid = $cordovaDevice.getUUID();
  }
  catch (err) {
    console.log("Error " + err.message);
    alert("error " + err.$$failure.message);
  }
};
init();

})

Html

Dash

{{uuid}}

You may only access cordova plugins within the ionic.Platform.ready() callback function:

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

.controller('DashCtrl', function ($scope, $state, $cordovaDevice) {

var init = function () {
  console.log("initializing device");
  try {

    $scope.uuid = $cordovaDevice.getUUID();

  }
  catch (err) {
    console.log("Error " + err.message);
    alert("error " + err.$$failure.message);
  }

};

ionic.Platform.ready(function(){
  init();
});

})

This is because Cordova plugins take some more time to load then the web application. The ionic.Platform.ready() callback is triggered as soon Cordova has fully loaded or immediately if it is already loaded.

2 Likes

Hi Alex,

Thanks for the reply. Iv added in this change.

sadly however it did not make a difference i still get {{uuid}} as the output rather than an actual uuid

Silly question, but I have to ask because I’ve forgotten it myself before. Did you actually install the plugin?

cordova plugin add org.apache.cordova.device

Yeah iv installed the plugin.

If i start a new project it works fine. i think iv narrowed it down to the include of ngCordova in my module not working

Do you have cordova.js above ng-cordova.min.js?