Search code examples
cordovaphonegap-pluginscordova-pluginsionic-framework

Ionic platform events not working


This worked fine until today, don't know does it have something with new release of Ionic or something else. This is what i have:

$ionicPlatform.ready(function() {
  if (window.cordova && window.cordova.plugins.Keyboard) {
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  }

  if (window.StatusBar) {
    // org.apache.cordova.statusbar required
    StatusBar.styleDefault();
  }

  $ionicPlatform.on('pause', function(){
    alert("pause");
    $rootScope.$broadcast('app-pause', {});
    $rootScope.$emit('app-pause', {});
  })

  $ionicPlatform.on('resume', function(){
    alert("resume");
  })

  $ionicPlatform.on('online', function(){
    alert("online");
  })

  $ionicPlatform.$on('offline', function(){
    alert("offline");
  })

});

None of these events work anymore. I have updated Cordova and Ionic but also added network-information plugin but nothing.

Any suggestions?


Solution

  • Try to use cordova way doing this

    var exampleApp = angular.module('example', ['ionic'])
    .run(function($ionicPlatform) {
        $ionicPlatform.ready(function() {
            document.addEventListener("resume", function() {
                console.log("The application is resuming from the background");
            }, false);
        });
    });