registerBackButtonAction not triggring

registerBackButtonAction is not triggering in device. what’s the problem i am using ionic 2.2.3 version help

// $ionicPlatform.registerBackButtonAction(function (event) {
// if($state.current.name==“menu.home”){
// navigator.app.exitApp();
// }
// else {
// navigator.app.backHistory();
// }
// }, 100);

tried this too no luck
// $ionicPlatform.registerBackButtonAction(function (event) {
// event.preventDefault();
// alert(“back button action handler”);
// }, 100);

is this something you are looking for http://stackoverflow.com/questions/30492011/ionic-registerbackbuttonaction-does-not-work ?

i did tried this too but no luck. is this cordova or ionic version problem? could not figure it out

What error you are getting ? Did you track console errors ? can you provide more code how you exactly using the code ?

there is no logs on pressing back button

This is the version of the Ionic CLI you have installed.
To get the version of Ionic Framework you are using please run ionic info on the command line.

Your system information:

Cordova CLI: 6.5.0
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
ios-deploy version: Not installed
ios-sim version: Not installed
OS: macOS Sierra
Node Version: v6.10.2
Xcode version: Xcode 8.3 Build version 8E162