# onNotification: why Handling a new push notification works only once

**URL:** <https://forum.ionicframework.com/t/onnotification-why-handling-a-new-push-notification-works-only-once/27729>\
**Category:** ionic-v1\
**Created:** [July 6, 2015, 12:30am UTC](https://forum.ionicframework.com/t/onnotification-why-handling-a-new-push-notification-works-only-once/27729 "2015-07-06T00:30:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![m2m](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/m2m/32/77446_2.png) [@m2m](https://forum.ionicframework.com/u/m2m)\
**Post date:** [July 6, 2015, 12:30am UTC](https://forum.ionicframework.com/t/onnotification-why-handling-a-new-push-notification-works-only-once/27729/1 "2015-07-06T00:30:02Z")

</div>

i have a sign up controller where i identify the user and register them for push notification. like so:

```
  function identifyUser(res) {
        console.log('Ionic User: Identifying with Ionic User service');

        var user = $ionicUser.get();
        if (ionic.Platform.isAndroid()) {
            $scope.platform = "Android"
        }
        user.user_id = res.data.user._id;
        // Add some metadata to your user object.
        angular.extend(user, {
            name: res.data.user.displayName,
            bio: 'I come from planet Ion',
            platform: $scope.platform
        });

        // Identify your user with the Ionic User Service
        $ionicUser.identify(user).then(function() {
            $scope.identified = true;
        });

    }; // identify User

    function pushRegister() {
        console.log('Ionic Push: Registering user');
        // Register with the Ionic Push service. All parameters are optional.
        $ionicPush.register({
            canShowAlert: false, //Can pushes show an alert on your screen?
            canSetBadge: true, //Can pushes update app icon badges?
            canPlaySound: true, //Can notifications play a sound?
            canRunActionsOnWake: false, //Can run actions outside the app,
            onNotification: function(notification) {
                // Handle new push notifications here
                console.log(notification);
                return true;
            }
        });

    }; // push Register 

$scope.authenticate = function(provider) {
        $auth.authenticate(provider)
            .then(function(res) {
                console.log('You are now Registered', res);
                identifyUser(res);
                var confirmPopup = $ionicPopup.confirm({
                    title: 'Allow push notification',
                    template: 'Allow push notification'
                });
                confirmPopup.then(function(res) {
                    if (res) {
                        if ($scope.identified) {
                            pushRegister();
                            console.log('You are sure');
                        }
                    } else {
                        console.log('You are not sure');
                    }
                });
                $state.go('app.categories');
            }, handleError);
    } 

```

However this work as long as i don’t terminate the app, if i did terminated the app and re-open it. still getting the push notifications but can’t handle them in my case i log them in the console for now.

```
     onNotification: function(notification) {
            // Handle new push notifications here
            console.log(notification);
            return true;
        }
```
