Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 821
Jack Avatar asked Mar 17 '23 18:03

Jack


2 Answers

You can try not wrapping it inside the platform ready event, the following is working for me on Android with version 1.3.0. Sitting inside app run.

    $ionicPlatform.on("resume", function(){
       setTimeout(function() {
           alert('doc resume 5');
       }, 0);
    });
like image 153
johnw86 Avatar answered Mar 23 '23 01:03

johnw86


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);
    });
});
like image 32
yernarun Avatar answered Mar 23 '23 00:03

yernarun