$ionicPlatform.on Undefined - using Beta14

I’m trying to use ionicPlatform.on() but I get undefined error.
in browser using serve and simulator using emulate

inspecting $ionicPlatform object gives me the below:

$backButtonActions: Object
_hasBackButtonHandler: true
hardwareBackButtonClick: function (e) {
is: function (type) {
offHardwareBackButton: function (fn) {
onHardwareBackButton: function (cb) {
ready: function (cb) {
registerBackButtonAction: function (fn, priority, actionId) {
__proto__: Object

running ionic info provides this output

OS: Mac OS X Yosemite
Node Version: v0.12.0
Cordova CLI: 4.2.0
Ionic Version: 1.0.0-beta.14
Ionic CLI Version: 1.3.11
Xcode version: Xcode 6.1.1 Build version 6A2008a 
ios-sim version: 3.1.1 

Looking at the docs - .on() should be available…
I’m not sure what I’m missing…

Hmm, seems to be working fine for me.

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    $ionicPlatform.on("resume", function() {
    $ionicPlatform.on("pause", function() {

Still getting an undefined for .on() (see error below)

  [Error] TypeError: undefined is not a function (evaluating '$ionicPlatform.on')
    	(anonymous function) (app.js, line 39)
    	(anonymous function) (ionic.bundle.js, line 36892)
    	onPlatformReady (ionic.bundle.js, line 2329)
    	onWindowLoad (ionic.bundle.js, line 2317)

– Relevant code from app.js

     .run(function($ionicPlatform, URLSchemeService)
        	$ionicPlatform.ready(function() {
        		console.log("App Is Ready");
        		//Custom Event Handling for Custom URL Scheme
        		window.addEventListener('URL', function(event)
    		$ionicPlatform.on('pause', function() {
    		   console.log("App Is Paused"); 
    		$ionicPlatform.on('resume', function()
    	           console.log("App Is Resumed"); 

Can you tell me what steps you took to get this?

I emulate the app with ionic emulate iOS -l -c
then get the output in terminal / Safari -> iOS simulator console

I created an app, wrote some services, added some plugins and then needed to track when app was background or foreground and added the code for .on()


  • ionic.keyboard
  • sqlite
  • branchmetrics
  • launchmyapp
  • socialsharing
  • cordova.console
  • cordova.device
  • cordova.inappbrowser
  • cordova.splashscreen
  • cordova.statusbar

Can you try with a blank project and see if everything works there?
It could be something going on with one of the plugins

This has become an issue for me too since I just upgraded to .14 from .13. Was working perfectly yesterday. Thanks

1 Like