title: $ionicPlatform.ready fires before deviceready
body: <p>I am working with Cordova and Ionic and trying to get the device uuid using the Cordova plugin and ngCordova for device (<a href="http://ngcordova.com/docs/plugins/device/" rel="nofollow">http://ngcordova.com/docs/plugins/device/</a>).</p>
  
  <p><strong>Problem</strong></p>
  
  <p>$cordovaDevice.getDevice() throws a device undefined error when running in the IonicView app installed on IPhone IOS 9.2.1 when called from $ionicPlatform.ready.  However, it works fine when called from deviceready event.  </p>
  
  <p>Interestingly, $ionicPlatform.ready works fine on Android device or Windows 8.1 device.</p>
  
  <p>Here is some code to recreate the problem:</p>
  
  <pre><code>angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter.services'])
  
  .run(function ($ionicPlatform, $cordovaDevice) {
  
  document.addEventListener('deviceready', onDeviceReady.bind(this), false);
  
  function onDeviceReady() {
  
      try {
          var device = $cordovaDevice.getDevice();
          alert("onDeviceReady Success!");
      } catch (e) {
          console.warn("onDeviceReady error: " + e)
          alert("onDeviceReady error: " + e);
      }
  };
  
  $ionicPlatform.ready(function () {
  
      try {
          var device = $cordovaDevice.getDevice();
          alert("ionicPlatform.ready Success!")
      } catch (e) {
          console.warn("ionicPlatform.ready error: " + e)
          alert("ionicPlatform.ready error: " + e);
      }
  });
  })
  </code></pre>
  
  <p>This code will produce 2 alerts with the following messages:</p>
  
  <ul>
  <li>"ionicPlatform.ready error: ReferenceError: Can't find variable:
  device"</li>
  <li>"onDeviceReady Success!"</li>
  </ul>
  
  <p>I really would expect that ionicPlatform.ready would not fire until the deviceready event fired.</p>
  
  <p>Any thoughts why this is happening or how to guarantee the device has been loaded before calling $cordovaDevice.getDevice();</p>
  
  <p>Thanks,
  Tom</p>