How $ionicPlatform.ready works?

Hello everybody,

I’m using ngCordova promises inside my services so I need to be sure deviceReady has been already called and I was using this code:

return $ionicPlatform.ready().then(
 function () {
  var aFunction = function () {
   return 'someValue';
  };

  return $ngCordovaFunction()
  .then(function (returnValue) {
   return aFunction();
  });
 });

I don’t use

$ionicPlatform.ready(function () { ... });

because, first of all, it doesn’t return a promise and then it is called just once. No matter how many times I need it, after first occurrence it doesn’t call others callback. The first is in app.js .run function, then no one $ionicPlatform.ready(…) in controllers or services are called. Just $ionicPlatform.ready().then(…) works. And I was ok with that. :grin:

Until Windows Phone.

On Windows Phone the first $ionicPlatform.ready(…) blocks every future calls to the same function, both $ionicPlatform.ready(…) and $ionicPlatform.ready().then(…) are ignored. If I switch app.js .run to $ionicPlatform.ready().then(…) then it let others ready().then(…) run but they are called twice. Every of them is called twice. Either with “ng-controller” and angular-ui routing.

Is it a bug? Or I’m missing something about it?
I could create a landing page to wait until deviceReady will be fired but it’s a workaround and I don’t like them…

Thank you to everyone who can give me some explanation… :smile: